Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
from shap_e.models.text_to_3d import create_model_and_diffusion
|
| 6 |
-
from shap_e.util.notebooks import decode_latent_mesh
|
| 7 |
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
model, diffusion = create_model_and_diffusion(batch_size=1, device=device)
|
| 12 |
-
model.eval()
|
| 13 |
|
| 14 |
def generate_3d(prompt):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
mesh.export(output_path)
|
| 29 |
-
return output_path
|
| 30 |
|
| 31 |
-
gr.Interface(
|
| 32 |
fn=generate_3d,
|
| 33 |
-
inputs=gr.Textbox(label="Prompt
|
| 34 |
-
outputs=gr.Model3D(label="3D
|
| 35 |
-
title="Text
|
| 36 |
-
description="Masukkan prompt
|
| 37 |
-
)
|
| 38 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
import tempfile
|
| 5 |
+
import trimesh
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
HF_TOKEN = os.getenv("HF_TOKEN") # token environment
|
| 8 |
|
| 9 |
+
client = InferenceClient(token=HF_TOKEN)
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def generate_3d(prompt):
|
| 12 |
+
result = client.text_to_mesh(
|
| 13 |
+
model="Webaverse/Stable-Dreamfusion",
|
| 14 |
+
inputs={"prompt": prompt, "num_steps": 100},
|
| 15 |
+
)
|
| 16 |
+
mesh_bytes = result["output"] # raw mesh bytes
|
| 17 |
+
temp = tempfile.NamedTemporaryFile(delete=False, suffix=".ply")
|
| 18 |
+
temp.write(mesh_bytes)
|
| 19 |
+
temp.flush()
|
| 20 |
+
# optionally convert to .glb
|
| 21 |
+
mesh = trimesh.load(temp.name)
|
| 22 |
+
glb_path = temp.name.replace(".ply", ".glb")
|
| 23 |
+
mesh.export(glb_path)
|
| 24 |
+
return glb_path
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
fn=generate_3d,
|
| 28 |
+
inputs=gr.Textbox(label="Prompt Game Asset"),
|
| 29 |
+
outputs=gr.Model3D(label="Generated 3D Asset (.glb)"),
|
| 30 |
+
title="Text‑to‑3D Game Asset (Dreamfusion)",
|
| 31 |
+
description="Masukkan prompt, hasil akan berupa file .glb yang siap impor ke game engine."
|
| 32 |
+
)
|
| 33 |
+
iface.launch()
|