Spaces:
Runtime error
Runtime error
Upload gradio_app.py
Browse files- gradio_app.py +9 -7
gradio_app.py
CHANGED
@@ -9,6 +9,7 @@ import gradio as gr
|
|
9 |
import trimesh
|
10 |
from transparent_background import Remover
|
11 |
from pathlib import Path
|
|
|
12 |
import subprocess
|
13 |
|
14 |
def install_cuda_toolkit():
|
@@ -210,14 +211,14 @@ def generate_and_process_3d(image: Image.Image) -> tuple[str | None, Image.Image
|
|
210 |
trimesh_mesh = trimesh_mesh[0]
|
211 |
|
212 |
# Export to GLB
|
213 |
-
|
214 |
-
|
215 |
-
output_path = os.path.join(OUTPUT_DIR,
|
216 |
-
|
217 |
|
218 |
trimesh_mesh.export(output_path, file_type="glb", include_normals=True)
|
219 |
|
220 |
-
return output_path
|
221 |
|
222 |
except Exception as e:
|
223 |
print(f"Error during generation: {str(e)}")
|
@@ -238,9 +239,10 @@ with gr.Blocks() as demo:
|
|
238 |
model_output = gr.Model3D(
|
239 |
label="Generated .GLB model",
|
240 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
|
|
241 |
)
|
242 |
-
|
243 |
-
|
244 |
# Event handler
|
245 |
input_img.upload(
|
246 |
fn=generate_and_process_3d,
|
|
|
9 |
import trimesh
|
10 |
from transparent_background import Remover
|
11 |
from pathlib import Path
|
12 |
+
import uuid
|
13 |
import subprocess
|
14 |
|
15 |
def install_cuda_toolkit():
|
|
|
211 |
trimesh_mesh = trimesh_mesh[0]
|
212 |
|
213 |
# Export to GLB
|
214 |
+
unique_id = str(uuid.uuid4())
|
215 |
+
filename = f'model_{unique_id}.glb'
|
216 |
+
output_path = os.path.join(OUTPUT_DIR, filename)
|
217 |
+
public_url = f"https://john6666-image-to-3d-test.hf.space/file={output_path}"
|
218 |
|
219 |
trimesh_mesh.export(output_path, file_type="glb", include_normals=True)
|
220 |
|
221 |
+
return output_path, public_url
|
222 |
|
223 |
except Exception as e:
|
224 |
print(f"Error during generation: {str(e)}")
|
|
|
239 |
model_output = gr.Model3D(
|
240 |
label="Generated .GLB model",
|
241 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
242 |
+
visible=False
|
243 |
)
|
244 |
+
output_url = gr.Textbox(label="Output URL", value="", lines=1, interactive=False)
|
245 |
+
|
246 |
# Event handler
|
247 |
input_img.upload(
|
248 |
fn=generate_and_process_3d,
|