Spaces:
Runtime error
Runtime error
File size: 2,565 Bytes
69fc467 bb82fad 69fc467 bb82fad 69fc467 bb82fad 69fc467 bb82fad 69fc467 bb82fad 69fc467 b4490fe 69fc467 bb82fad 69fc467 bb82fad 69fc467 bb82fad 69fc467 bb82fad 69fc467 38585d8 62a6e29 bb82fad 69fc467 adb2058 69fc467 bb82fad 69fc467 bb82fad f04eda2 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
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("""
<center><h1 style="color:#fff">3d Model Generater</h1></center>""")
with gr.Row():
api_key=gr.Textbox(label="API key",placeholder="API key from meshy website")
with gr.Row():
prompt=gr.Textbox(label="Prompt",placeholder="Describe the 3d structure")
with gr.Row():
output=gr.Model3D()
with gr.Row():
button=gr.Button()
button.click(self._download_3d,[prompt,api_key],output)
demo.launch(debug=True)
if __name__=="__main__":
result=Model3d_generater()
result.interface() |