File size: 1,675 Bytes
f3d5c36 58a6f69 67e0e4f 58a6f69 49fb9a3 29c62a9 9ebbc97 2ed15be 67e0e4f f3d5c36 67e0e4f 2ed15be 67e0e4f 2ed15be 67e0e4f 2ed15be 67e0e4f 2ed15be f3d5c36 67e0e4f 2ed15be 67e0e4f 2ed15be 67e0e4f 29c62a9 58a6f69 33ab927 29c62a9 67e0e4f |
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 48 49 50 51 52 53 54 |
import gradio as gr
import replicate
import requests
import os
import uuid
# Set your Replicate API token
os.environ["REPLICATE_API_TOKEN"] = "r8_FqBcLY8OR6F3Fsf4D4fT415tb1CN3790UGzYE"
def generate_3d(prompt):
print("Prompt received:", prompt) # Check if button works
def generate_3d(prompt):
print("Prompt received:", prompt)
try:
output = replicate.run(
"openai/shap-e:9c9ecb8d35d0cc0ecde68b8a0d4a2f94f2bc6ee9393e8c3d76c44d7c0d75b1f9",
input={
"prompt": prompt,
"guidance_scale": 15,
"num_inference_steps": 64
}
)
print("Replicate output:", output)
if not output or not isinstance(output, list):
return "Error: No model output."
glb_url = output[0]
print("GLB URL:", glb_url)
response = requests.get(glb_url)
if response.status_code != 200:
print("Download failed with status:", response.status_code)
return f"Download failed: {response.status_code}"
file_name = f"{uuid.uuid4()}.glb"
with open(file_name, 'wb') as f:
f.write(response.content)
print("Saved to:", file_name)
return file_name
except Exception as e:
print("Exception occurred:", str(e))
return f"Generation failed: {str(e)}"
with gr.Blocks() as demo:
gr.Markdown("## 3D Model Generator (Text to 3D)")
prompt = gr.Textbox(label="Prompt", placeholder="e.g. A sci-fi sword")
output = gr.Model3D(label="Generated 3D Model")
btn = gr.Button("Generate")
btn.click(fn=generate_3d, inputs=prompt, outputs=output)
demo.launch() |