Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,39 @@
|
|
1 |
-
import gradio as gr
|
2 |
import replicate
|
|
|
3 |
import os
|
4 |
import uuid
|
5 |
|
6 |
# Set your Replicate API token
|
7 |
os.environ["REPLICATE_API_TOKEN"] = "r8_FqBcLY8OR6F3Fsf4D4fT415tb1CN3790UGzYE"
|
8 |
|
9 |
-
import requests
|
10 |
-
|
11 |
def generate_3d(prompt):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("## 3D Model Generator (Text to 3D)")
|
24 |
prompt = gr.Textbox(label="Prompt", placeholder="e.g. A sci-fi sword")
|
@@ -27,4 +42,4 @@ with gr.Blocks() as demo:
|
|
27 |
btn = gr.Button("Generate")
|
28 |
btn.click(fn=generate_3d, inputs=prompt, outputs=output)
|
29 |
|
30 |
-
demo.launch()
|
|
|
1 |
+
import import gradio as gr
|
2 |
import replicate
|
3 |
+
import requests
|
4 |
import os
|
5 |
import uuid
|
6 |
|
7 |
# Set your Replicate API token
|
8 |
os.environ["REPLICATE_API_TOKEN"] = "r8_FqBcLY8OR6F3Fsf4D4fT415tb1CN3790UGzYE"
|
9 |
|
|
|
|
|
10 |
def generate_3d(prompt):
|
11 |
+
try:
|
12 |
+
output = replicate.run(
|
13 |
+
"openai/shap-e:9c9ecb8d35d0cc0ecde68b8a0d4a2f94f2bc6ee9393e8c3d76c44d7c0d75b1f9",
|
14 |
+
input={"prompt": prompt, "guidance_scale": 15, "num_inference_steps": 64}
|
15 |
+
)
|
16 |
+
|
17 |
+
print("REPLICATE OUTPUT:", output)
|
18 |
+
|
19 |
+
if not output or not isinstance(output, list):
|
20 |
+
return "Error: No model output."
|
21 |
+
|
22 |
+
glb_url = output[0]
|
23 |
+
response = requests.get(glb_url)
|
24 |
+
|
25 |
+
if response.status_code != 200:
|
26 |
+
return f"Failed to download GLB file. Status code: {response.status_code}"
|
27 |
+
|
28 |
+
file_name = f"{uuid.uuid4()}.glb"
|
29 |
+
with open(file_name, 'wb') as f:
|
30 |
+
f.write(response.content)
|
31 |
+
|
32 |
+
return file_name
|
33 |
+
|
34 |
+
except Exception as e:
|
35 |
+
return f"Generation failed: {str(e)}"
|
36 |
+
|
37 |
with gr.Blocks() as demo:
|
38 |
gr.Markdown("## 3D Model Generator (Text to 3D)")
|
39 |
prompt = gr.Textbox(label="Prompt", placeholder="e.g. A sci-fi sword")
|
|
|
42 |
btn = gr.Button("Generate")
|
43 |
btn.click(fn=generate_3d, inputs=prompt, outputs=output)
|
44 |
|
45 |
+
demo.launch()
|