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