Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import os | |
| # Get Hugging Face API key from the secret you just saved | |
| API_URL = "https://api-inference.huggingface.co/models/TripoSR/TripoSR" | |
| headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"} | |
| def generate_3d(image): | |
| try: | |
| with open(image, "rb") as f: | |
| response = requests.post(API_URL, headers=headers, files={"file": f}) | |
| if response.status_code == 200: | |
| # Save the model locally | |
| output_path = "output.glb" | |
| with open(output_path, "wb") as out_file: | |
| out_file.write(response.content) | |
| return output_path # Gradio will let user download it | |
| else: | |
| return f"Error: {response.text}" | |
| except Exception as e: | |
| return f"An error occurred: {str(e)}" | |
| iface = gr.Interface( | |
| fn=generate_3d, | |
| inputs=gr.Image(type="filepath", label="Upload 2D Image"), | |
| outputs="file", # change here | |
| title="Scan Spectrum - 2D to 3D Converter", | |
| description="Upload any 2D image to generate a realistic 3D model you can download.", | |
| ) | |
| iface.launch() | |