Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
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')}"}
|
@@ -10,12 +11,21 @@ def generate_3d_from_image(image):
|
|
10 |
response = requests.post(API_URL, headers=HEADERS, files={"file": f})
|
11 |
|
12 |
if response.status_code == 200:
|
13 |
-
|
14 |
-
with open(
|
15 |
out_file.write(response.content)
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
else:
|
18 |
-
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
gr.Markdown("## 馃 Genera un modelo 3D real desde una imagen usando TripoSR")
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
+
import zipfile
|
5 |
|
6 |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/TripoSR"
|
7 |
HEADERS = {"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"}
|
|
|
11 |
response = requests.post(API_URL, headers=HEADERS, files={"file": f})
|
12 |
|
13 |
if response.status_code == 200:
|
14 |
+
output_zip = "model_output.zip"
|
15 |
+
with open(output_zip, "wb") as out_file:
|
16 |
out_file.write(response.content)
|
17 |
+
|
18 |
+
# Intentar extraer un archivo .glb o .ply desde el zip
|
19 |
+
with zipfile.ZipFile(output_zip, 'r') as zip_ref:
|
20 |
+
zip_ref.extractall("output_model")
|
21 |
+
|
22 |
+
for filename in zip_ref.namelist():
|
23 |
+
if filename.endswith(".glb") or filename.endswith(".ply"):
|
24 |
+
return os.path.join("output_model", filename)
|
25 |
+
|
26 |
+
raise gr.Error("El modelo no gener贸 un archivo .glb o .ply compatible.")
|
27 |
else:
|
28 |
+
raise gr.Error(f"Error {response.status_code}: {response.text}")
|
29 |
|
30 |
with gr.Blocks() as demo:
|
31 |
gr.Markdown("## 馃 Genera un modelo 3D real desde una imagen usando TripoSR")
|