Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,29 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
return "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF-Binary/Duck.glb"
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
|
|
|
|
11 |
with gr.Row():
|
12 |
-
image_input = gr.Image(type="filepath", label="Sube
|
13 |
-
|
14 |
-
|
15 |
-
output = gr.Model3D(label="Vista previa del modelo 3D")
|
16 |
|
17 |
-
|
18 |
|
19 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
|
5 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/TripoSR"
|
6 |
+
HEADERS = {"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"}
|
|
|
7 |
|
8 |
+
def generate_3d_from_image(image):
|
9 |
+
with open(image, "rb") as f:
|
10 |
+
response = requests.post(API_URL, headers=HEADERS, files={"file": f})
|
11 |
+
|
12 |
+
if response.status_code == 200:
|
13 |
+
output_path = "output.glb"
|
14 |
+
with open(output_path, "wb") as out_file:
|
15 |
+
out_file.write(response.content)
|
16 |
+
return output_path
|
17 |
+
else:
|
18 |
+
return f"Error: {response.status_code} - {response.text}"
|
19 |
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown("## 馃 Genera un modelo 3D real desde una imagen usando TripoSR")
|
22 |
with gr.Row():
|
23 |
+
image_input = gr.Image(type="filepath", label="Sube una imagen (.png o .jpg)")
|
24 |
+
generate_btn = gr.Button("Generar modelo 3D")
|
25 |
+
output_model = gr.Model3D(label="Vista previa del modelo 3D")
|
|
|
26 |
|
27 |
+
generate_btn.click(fn=generate_3d_from_image, inputs=image_input, outputs=output_model)
|
28 |
|
29 |
demo.launch()
|