Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python | |
| import gradio as gr | |
| import PIL.Image | |
| from gradio_client import Client | |
| lgm_mini_client = Client("dylanebert/LGM-mini") | |
| triposr_client = Client("stabilityai/TripoSR") | |
| def run(image, model_name): | |
| file_path = "temp.png" | |
| image.save(file_path) | |
| print(file_path) | |
| model_name = model_name.lower() | |
| if model_name=='lgm-mini': | |
| result = lgm_mini_client.predict( | |
| file_path, # filepath in 'image' Image component | |
| api_name="/run" | |
| ) | |
| output = result | |
| elif model_name=='triposr': | |
| process_result = triposr_client.predict( | |
| file_path, # filepath in 'Input Image' Image component | |
| True, # bool in 'Remove Background' Checkbox component | |
| 0.85, # float (numeric value between 0.5 and 1.0) in 'Foreground Ratio' Slider component | |
| api_name="/preprocess") | |
| print(type(process_result)) | |
| result = triposr_client.predict( | |
| process_result, # filepath in 'Processed Image' Image component | |
| 256, # float (numeric value between 32 and 320) in 'Marching Cubes Resolution' Slider component | |
| api_name="/generate") | |
| output = result[0] | |
| return output | |
| with gr.Blocks() as demo: | |
| with gr.Group(): | |
| with gr.Row(variant='panel'): | |
| with gr.Column(scale=1): | |
| image = gr.Image(label="Input image", show_label=False, type="pil", height=180) | |
| model_name = gr.Textbox(label="Model name", show_label=False) | |
| run_button = gr.Button("Run") | |
| with gr.Column(scale=1): | |
| result = gr.Model3D(label="Result", show_label=False) | |
| run_button.click( | |
| fn=run, | |
| inputs=[ | |
| image, | |
| model_name | |
| ], | |
| outputs=result, | |
| api_name="synthesize" | |
| ) | |
| demo.launch() |