Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,47 @@
|
|
1 |
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 |
-
print("Prompt received:", prompt) # Check if button works
|
12 |
-
def generate_3d(prompt):
|
13 |
-
print("Prompt received:", prompt)
|
14 |
try:
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
)
|
19 |
-
print("Replicate output:", output)
|
20 |
|
21 |
-
|
22 |
-
return "Error: No model output."
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
response = requests.get(
|
28 |
if response.status_code != 200:
|
29 |
-
print("Download failed
|
30 |
-
return
|
31 |
|
32 |
file_name = f"{uuid.uuid4()}.glb"
|
33 |
with open(file_name, 'wb') as f:
|
34 |
f.write(response.content)
|
35 |
|
36 |
-
print("Saved to:", file_name)
|
37 |
return file_name
|
38 |
|
39 |
except Exception as e:
|
40 |
-
print("Exception
|
41 |
-
return
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
import replicate
|
3 |
import requests
|
|
|
4 |
import uuid
|
5 |
+
import os
|
6 |
|
7 |
+
# Set your Replicate API token securely
|
8 |
os.environ["REPLICATE_API_TOKEN"] = "r8_FqBcLY8OR6F3Fsf4D4fT415tb1CN3790UGzYE"
|
9 |
|
10 |
def generate_3d(prompt):
|
|
|
|
|
|
|
11 |
try:
|
12 |
+
print("Prompt received:", prompt)
|
13 |
+
|
14 |
+
output = replicate.run(
|
15 |
+
"lucataco/text-to-3d:e461273fe25ac0b2b3fe14b7551636ee58b78f12fe25aa0f141e4cd32b2f3c2d",
|
16 |
+
input={"prompt": prompt}
|
17 |
)
|
|
|
18 |
|
19 |
+
print("Model output:", output)
|
|
|
20 |
|
21 |
+
if not output or not isinstance(output, str):
|
22 |
+
return None
|
23 |
|
24 |
+
response = requests.get(output)
|
25 |
if response.status_code != 200:
|
26 |
+
print("Download failed:", response.status_code)
|
27 |
+
return None
|
28 |
|
29 |
file_name = f"{uuid.uuid4()}.glb"
|
30 |
with open(file_name, 'wb') as f:
|
31 |
f.write(response.content)
|
32 |
|
|
|
33 |
return file_name
|
34 |
|
35 |
except Exception as e:
|
36 |
+
print("Exception:", str(e))
|
37 |
+
return None
|
38 |
+
|
39 |
+
demo = gr.Interface(
|
40 |
+
fn=generate_3d,
|
41 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
42 |
+
outputs=gr.Model3D(label="Generated 3D Model"),
|
43 |
+
title="Text to 3D Model Viewer",
|
44 |
+
description="Enter a prompt to generate and view a 3D model",
|
45 |
+
)
|
46 |
+
|
47 |
+
demo.launch(share=True)
|