Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -4,58 +4,64 @@ import time | |
| 4 | 
             
            import os 
         | 
| 5 | 
             
            class Model3d_generater:
         | 
| 6 |  | 
| 7 | 
            -
              def __init__(self):
         | 
| 8 | 
            -
                api_key = os.getenv("MESHY_API_KEY")
         | 
| 9 | 
            -
                self.headers = {
         | 
| 10 | 
            -
                  "Authorization": f"Bearer {api_key}"
         | 
| 11 | 
            -
                  }
         | 
| 12 | 
             
                self.query=''
         | 
| 13 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 14 |  | 
|  | |
| 15 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
                   | 
| 18 | 
            -
                  print(f"query is {self.query}")
         | 
| 19 | 
            -
                  payload = {
         | 
| 20 | 
            -
                  "mode": "preview",
         | 
| 21 | 
            -
                  "prompt":query,
         | 
| 22 | 
            -
                  "art_style": "realistic",
         | 
| 23 | 
            -
                  "seed":1565957778,
         | 
| 24 | 
            -
                  "negative_prompt":"messy hands and feet, blurry mess, three eyes",
         | 
| 25 | 
            -
                  "texture_richness":"high"
         | 
| 26 | 
             
                  }
         | 
| 27 |  | 
| 28 | 
            -
                   | 
| 29 | 
            -
                  "https://api.meshy.ai/v2/text-to-3d",
         | 
| 30 | 
            -
                  headers=self.headers,
         | 
| 31 | 
            -
                  json=payload,
         | 
| 32 | 
            -
                  )
         | 
| 33 | 
            -
                  task_id=generate_3d.json()["result"]
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  return task_id
         | 
| 36 | 
            -
              def _get_task_id_(self,query):
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                try:
         | 
| 39 | 
            -
                  task_id=self._generate_3d_(query)
         | 
| 40 |  | 
| 41 | 
             
                  time.sleep(50)
         | 
| 42 |  | 
| 43 | 
             
                  get_asset= requests.get(
         | 
| 44 | 
             
                    f"https://api.meshy.ai/v2/text-to-3d/{task_id}",
         | 
| 45 | 
            -
                    headers= | 
| 46 | 
             
                    )
         | 
| 47 |  | 
| 48 |  | 
| 49 | 
             
                  download_3d=get_asset.json()["model_urls"]["glb"]
         | 
| 50 | 
            -
             | 
| 51 | 
             
                  return download_3d
         | 
| 52 | 
             
                except:
         | 
| 53 | 
             
                  print("error on _get_task_id_")
         | 
| 54 |  | 
| 55 | 
            -
              def _download_3d(self,query):
         | 
| 56 | 
             
                try:
         | 
| 57 |  | 
| 58 | 
            -
                  download_3d=self._get_task_id_(query)
         | 
| 59 | 
             
                  response = requests.get(download_3d, allow_redirects=False)
         | 
| 60 | 
             
                  short_filename = '3d_asset.glb'  # Change 'my_file.ext' to whatever you prefer, with the correct extension
         | 
| 61 |  | 
| @@ -71,6 +77,9 @@ class Model3d_generater: | |
| 71 | 
             
                  gr.HTML("""
         | 
| 72 | 
             
                        <center><h1 style="color:#fff">3d Model Generater</h1></center>""")
         | 
| 73 |  | 
|  | |
|  | |
|  | |
| 74 | 
             
                  with gr.Row():
         | 
| 75 | 
             
                    prompt=gr.Textbox(label="Prompt")
         | 
| 76 |  | 
| @@ -79,9 +88,9 @@ class Model3d_generater: | |
| 79 | 
             
                  with gr.Row():
         | 
| 80 | 
             
                    button=gr.Button()
         | 
| 81 |  | 
| 82 | 
            -
                  button.click(self._download_3d,prompt,output)
         | 
| 83 |  | 
| 84 | 
            -
                demo.launch()
         | 
| 85 |  | 
| 86 | 
             
            if __name__=="__main__":
         | 
| 87 | 
             
              result=Model3d_generater()
         | 
|  | |
| 4 | 
             
            import os 
         | 
| 5 | 
             
            class Model3d_generater:
         | 
| 6 |  | 
| 7 | 
            +
              def __init__(self,):
         | 
|  | |
|  | |
|  | |
|  | |
| 8 | 
             
                self.query=''
         | 
| 9 |  | 
| 10 | 
            +
              def _generate_3d_(self,query,api_key):
         | 
| 11 | 
            +
                  #api key from meshy website
         | 
| 12 | 
            +
                  try:
         | 
| 13 | 
            +
                    headers = {
         | 
| 14 | 
            +
                    "Authorization": f"Bearer {api_key}"
         | 
| 15 | 
            +
                    }
         | 
| 16 | 
            +
                    self.query = query
         | 
| 17 | 
            +
                    # print(f"query is {self.query}")
         | 
| 18 | 
            +
                    payload = {
         | 
| 19 | 
            +
                    "mode": "preview",
         | 
| 20 | 
            +
                    "prompt":query,
         | 
| 21 | 
            +
                    "art_style": "realistic",
         | 
| 22 | 
            +
                    "seed":1565957778,
         | 
| 23 | 
            +
                    "negative_prompt":"messy hands and feet, blurry mess, three eyes",
         | 
| 24 | 
            +
                    "texture_richness":"high"
         | 
| 25 | 
            +
                    }
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    generate_3d= requests.post(
         | 
| 28 | 
            +
                    "https://api.meshy.ai/v2/text-to-3d",
         | 
| 29 | 
            +
                    headers=headers,
         | 
| 30 | 
            +
                    json=payload,
         | 
| 31 | 
            +
                    )
         | 
| 32 | 
            +
                    task_id=generate_3d.json()["result"]
         | 
| 33 | 
            +
                   
         | 
| 34 | 
            +
                    return task_id
         | 
| 35 | 
            +
                  except Exception as e:
         | 
| 36 | 
            +
                    print("Error:",e)
         | 
| 37 | 
            +
              def _get_task_id_(self,query,api_key):
         | 
| 38 |  | 
| 39 | 
            +
                try:
         | 
| 40 |  | 
| 41 | 
            +
                  headers = {
         | 
| 42 | 
            +
                  "Authorization": f"Bearer {api_key}"
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 43 | 
             
                  }
         | 
| 44 |  | 
| 45 | 
            +
                  task_id=self._generate_3d_(query,api_key)
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 46 |  | 
| 47 | 
             
                  time.sleep(50)
         | 
| 48 |  | 
| 49 | 
             
                  get_asset= requests.get(
         | 
| 50 | 
             
                    f"https://api.meshy.ai/v2/text-to-3d/{task_id}",
         | 
| 51 | 
            +
                    headers=headers,
         | 
| 52 | 
             
                    )
         | 
| 53 |  | 
| 54 |  | 
| 55 | 
             
                  download_3d=get_asset.json()["model_urls"]["glb"]
         | 
| 56 | 
            +
                 
         | 
| 57 | 
             
                  return download_3d
         | 
| 58 | 
             
                except:
         | 
| 59 | 
             
                  print("error on _get_task_id_")
         | 
| 60 |  | 
| 61 | 
            +
              def _download_3d(self,query,api_key):
         | 
| 62 | 
             
                try:
         | 
| 63 |  | 
| 64 | 
            +
                  download_3d=self._get_task_id_(query,api_key)
         | 
| 65 | 
             
                  response = requests.get(download_3d, allow_redirects=False)
         | 
| 66 | 
             
                  short_filename = '3d_asset.glb'  # Change 'my_file.ext' to whatever you prefer, with the correct extension
         | 
| 67 |  | 
|  | |
| 77 | 
             
                  gr.HTML("""
         | 
| 78 | 
             
                        <center><h1 style="color:#fff">3d Model Generater</h1></center>""")
         | 
| 79 |  | 
| 80 | 
            +
                  with gr.Row():
         | 
| 81 | 
            +
                        api_key=gr.Textbox(label="API key",placeholder="API key from meshy website")
         | 
| 82 | 
            +
             | 
| 83 | 
             
                  with gr.Row():
         | 
| 84 | 
             
                    prompt=gr.Textbox(label="Prompt")
         | 
| 85 |  | 
|  | |
| 88 | 
             
                  with gr.Row():
         | 
| 89 | 
             
                    button=gr.Button()
         | 
| 90 |  | 
| 91 | 
            +
                  button.click(self._download_3d,[prompt,api_key],output)
         | 
| 92 |  | 
| 93 | 
            +
                demo.launch(debug=True)
         | 
| 94 |  | 
| 95 | 
             
            if __name__=="__main__":
         | 
| 96 | 
             
              result=Model3d_generater()
         | 
