import requests import gradio as gr import time import os class Model3d_generater: def __init__(self,): self.query='' def _generate_3d_(self,query,api_key): #api key from meshy website try: headers = { "Authorization": f"Bearer {api_key}" } self.query = query # print(f"query is {self.query}") payload = { "mode": "preview", "prompt":query, "art_style": "realistic", "seed":1565957778, "negative_prompt":"messy hands and feet, blurry mess, three eyes", "texture_richness":"high" } generate_3d= requests.post( "https://api.meshy.ai/v2/text-to-3d", headers=headers, json=payload, ) task_id=generate_3d.json()["result"] return task_id except Exception as e: print("Error:",e) def _get_task_id_(self,query,api_key): try: headers = { "Authorization": f"Bearer {api_key}" } task_id=self._generate_3d_(query,api_key) time.sleep(50) get_asset= requests.get( f"https://api.meshy.ai/v2/text-to-3d/{task_id}", headers=headers, ) download_3d=get_asset.json()["model_urls"]["glb"] return download_3d except: print("error on _get_task_id_") def _download_3d(self,query,api_key): try: download_3d=self._get_task_id_(query,api_key) response = requests.get(download_3d, allow_redirects=False) short_filename = '3d_asset.glb' # Change 'my_file.ext' to whatever you prefer, with the correct extension with open(short_filename, 'wb') as file: file.write(response.content) return short_filename except: print("error on _download_3d") def interface(self): with gr.Blocks(css=""".gradio-container {background: rgb(157,228,255); background: radial-gradient(circle, rgba(157,228,255,1) 0%, rgba(18,115,106,1) 100%);}""") as demo: gr.HTML("""