Spaces:
Runtime error
Runtime error
add some features
Browse files
Rodin.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import socketio
|
2 |
import requests
|
3 |
import json
|
|
|
4 |
import random
|
5 |
import base64
|
6 |
import io
|
@@ -135,8 +136,12 @@ class Generator:
|
|
135 |
|
136 |
mesh_response = rodin_mesh(prompt=prompt, group_uuid=None, settings=settings, images=images, name="images.jpeg", token=self.token)
|
137 |
progress_checker = JobStatusChecker(BASE_URL, mesh_response['job']['subscription_key'])
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
140 |
task_uuid = mesh_response['uuid'] # The task_uuid should be same during whole generation process
|
141 |
else:
|
142 |
new_prompt = prompt
|
@@ -151,7 +156,11 @@ class Generator:
|
|
151 |
# Check progress
|
152 |
subscription_key = update_response['job']['subscription_key']
|
153 |
checker = JobStatusChecker(BASE_URL, subscription_key)
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
|
156 |
preview_image = next(reversed(rodin_history(task_uuid, self.token).items()))[1]["preview_image"]
|
157 |
# print(f"Preview image URL: {rodin_history(task_uuid, self.token)}")
|
|
|
1 |
import socketio
|
2 |
import requests
|
3 |
import json
|
4 |
+
import time
|
5 |
import random
|
6 |
import base64
|
7 |
import io
|
|
|
136 |
|
137 |
mesh_response = rodin_mesh(prompt=prompt, group_uuid=None, settings=settings, images=images, name="images.jpeg", token=self.token)
|
138 |
progress_checker = JobStatusChecker(BASE_URL, mesh_response['job']['subscription_key'])
|
139 |
+
try:
|
140 |
+
progress_checker.start()
|
141 |
+
except Exception as e:
|
142 |
+
print(f"Error in generating mesh: {e}")
|
143 |
+
time.sleep(5)
|
144 |
+
|
145 |
task_uuid = mesh_response['uuid'] # The task_uuid should be same during whole generation process
|
146 |
else:
|
147 |
new_prompt = prompt
|
|
|
156 |
# Check progress
|
157 |
subscription_key = update_response['job']['subscription_key']
|
158 |
checker = JobStatusChecker(BASE_URL, subscription_key)
|
159 |
+
try:
|
160 |
+
checker.start()
|
161 |
+
except Exception as e:
|
162 |
+
print(f"Error in updating mesh: {e}")
|
163 |
+
time.sleep(5)
|
164 |
|
165 |
preview_image = next(reversed(rodin_history(task_uuid, self.token).items()))[1]["preview_image"]
|
166 |
# print(f"Preview image URL: {rodin_history(task_uuid, self.token)}")
|
app.py
CHANGED
@@ -91,8 +91,8 @@ def handle_prompt_change(prompt):
|
|
91 |
|
92 |
return hint_list
|
93 |
|
94 |
-
def
|
95 |
-
return ""
|
96 |
|
97 |
def return_render(image):
|
98 |
image = Image.fromarray(image)
|
@@ -155,14 +155,12 @@ with gr.Blocks() as demo:
|
|
155 |
cache_task_uuid = gr.Text(value="", visible=False)
|
156 |
|
157 |
# button_generate.click(fn=return_render, inputs=[block_image], outputs=[raw_image, fake3d])
|
158 |
-
block_image.
|
159 |
fn=do_nothing,
|
160 |
-
js=
|
161 |
inputs=[cacha_empty],
|
162 |
outputs=[cacha_empty]
|
163 |
-
).
|
164 |
-
|
165 |
-
button_generate.click(
|
166 |
fn=generator.preprocess,
|
167 |
inputs=[block_prompt, block_image, cache_image_base64, cache_task_uuid],
|
168 |
outputs=[block_prompt, cache_image_base64],
|
@@ -171,12 +169,31 @@ with gr.Blocks() as demo:
|
|
171 |
fn=generator.generate_mesh,
|
172 |
inputs=[block_prompt, cache_image_base64, cache_task_uuid],
|
173 |
outputs=[cache_raw_image, cache_task_uuid, fake3d],
|
174 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
fn=do_nothing,
|
176 |
js=change_button_name,
|
177 |
inputs=[cacha_empty],
|
178 |
outputs=[cacha_empty]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
)
|
|
|
180 |
block_default.click(fn=crop_image_default, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|
181 |
block_metal.click(fn=crop_image_metal, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|
182 |
block_contrast.click(fn=crop_image_contrast, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|
|
|
91 |
|
92 |
return hint_list
|
93 |
|
94 |
+
def clear_task():
|
95 |
+
return "", "", [], None
|
96 |
|
97 |
def return_render(image):
|
98 |
image = Image.fromarray(image)
|
|
|
155 |
cache_task_uuid = gr.Text(value="", visible=False)
|
156 |
|
157 |
# button_generate.click(fn=return_render, inputs=[block_image], outputs=[raw_image, fake3d])
|
158 |
+
block_image.upload(
|
159 |
fn=do_nothing,
|
160 |
+
js=change_button_name,
|
161 |
inputs=[cacha_empty],
|
162 |
outputs=[cacha_empty]
|
163 |
+
).success(
|
|
|
|
|
164 |
fn=generator.preprocess,
|
165 |
inputs=[block_prompt, block_image, cache_image_base64, cache_task_uuid],
|
166 |
outputs=[block_prompt, cache_image_base64],
|
|
|
169 |
fn=generator.generate_mesh,
|
170 |
inputs=[block_prompt, cache_image_base64, cache_task_uuid],
|
171 |
outputs=[cache_raw_image, cache_task_uuid, fake3d],
|
172 |
+
)
|
173 |
+
|
174 |
+
block_image.clear(
|
175 |
+
fn=do_nothing,
|
176 |
+
js=reset_button_name,
|
177 |
+
inputs=[cacha_empty],
|
178 |
+
outputs=[cacha_empty]
|
179 |
+
).then(fn=clear_task, outputs=[cache_task_uuid, block_prompt, block_prompt_hint, fake3d], show_progress="hidden")
|
180 |
+
|
181 |
+
button_generate.click(
|
182 |
fn=do_nothing,
|
183 |
js=change_button_name,
|
184 |
inputs=[cacha_empty],
|
185 |
outputs=[cacha_empty]
|
186 |
+
).success(
|
187 |
+
fn=generator.preprocess,
|
188 |
+
inputs=[block_prompt, block_image, cache_image_base64, cache_task_uuid],
|
189 |
+
outputs=[block_prompt, cache_image_base64],
|
190 |
+
show_progress="minimal"
|
191 |
+
).success(
|
192 |
+
fn=generator.generate_mesh,
|
193 |
+
inputs=[block_prompt, cache_image_base64, cache_task_uuid],
|
194 |
+
outputs=[cache_raw_image, cache_task_uuid, fake3d],
|
195 |
)
|
196 |
+
|
197 |
block_default.click(fn=crop_image_default, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|
198 |
block_metal.click(fn=crop_image_metal, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|
199 |
block_contrast.click(fn=crop_image_contrast, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|