Spaces:
Runtime error
Runtime error
RamAnanth1
commited on
Commit
•
4d5296b
1
Parent(s):
b876f6c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import PIL.Image
|
5 |
+
|
6 |
+
from gradio_client import Client
|
7 |
+
|
8 |
+
shap_e_client = Client("hysts/Shap-E")
|
9 |
+
triposr_client = Client("stabilityai/TripoSR")
|
10 |
+
|
11 |
+
|
12 |
+
def run(image, model_name):
|
13 |
+
if model_name=='Shape-E':
|
14 |
+
result = shap_e_client.predict(
|
15 |
+
image, # filepath in 'Input image' Image component
|
16 |
+
0, # float (numeric value between 0 and 2147483647) in 'Seed' Slider component
|
17 |
+
1, # float (numeric value between 1 and 20) in 'Guidance scale' Slider component
|
18 |
+
2, # float (numeric value between 2 and 100) in 'Number of inference steps' Slider component
|
19 |
+
api_name="/image-to-3d")
|
20 |
+
|
21 |
+
elif model_name=='TripoSR':
|
22 |
+
|
23 |
+
process_result = triposr_client.predict(
|
24 |
+
image, # filepath in 'Input Image' Image component
|
25 |
+
True, # bool in 'Remove Background' Checkbox component
|
26 |
+
0.5, # float (numeric value between 0.5 and 1.0) in 'Foreground Ratio' Slider component
|
27 |
+
api_name="/preprocess")
|
28 |
+
print(process_result)
|
29 |
+
|
30 |
+
result = triposr_client.predict(
|
31 |
+
process_result, # filepath in 'Processed Image' Image component
|
32 |
+
32, # float (numeric value between 32 and 320) in 'Marching Cubes Resolution' Slider component
|
33 |
+
api_name="/generate")
|
34 |
+
|
35 |
+
|
36 |
+
return result
|
37 |
+
|
38 |
+
|
39 |
+
with gr.Blocks() as demo:
|
40 |
+
with gr.Group():
|
41 |
+
image = gr.Image(label="Input image", show_label=False, type="pil")
|
42 |
+
model_name = gr.Textbox(label="Model name", show_label=False)
|
43 |
+
run_button = gr.Button("Run")
|
44 |
+
result = gr.Model3D(label="Result", show_label=False)
|
45 |
+
|
46 |
+
run_button.click(
|
47 |
+
fn=run,
|
48 |
+
inputs=[
|
49 |
+
image,
|
50 |
+
model_name
|
51 |
+
],
|
52 |
+
outputs=result,
|
53 |
+
api_name="synthesize",
|
54 |
+
concurrency_id="gpu",
|
55 |
+
concurrency_limit=1,
|
56 |
+
)
|