Spaces:
Runtime error
Runtime error
fix bugs
Browse files- Rodin.py +12 -9
- app.py +61 -12
- assets/00.png +0 -0
- assets/07.png +0 -0
- assets/08.png +0 -0
- assets/11.png +0 -0
- assets/13.png +0 -0
- assets/21.png +0 -0
- assets/24.PNG +0 -0
- assets/30.png +0 -0
- assets/42.png +0 -0
- assets/46.png +0 -0
- constant.py +1 -0
Rodin.py
CHANGED
@@ -28,6 +28,7 @@ def login(email, password):
|
|
28 |
log("INFO", f"Logged successfully")
|
29 |
user_uuid = response_data['user_uuid']
|
30 |
token = response_data['token']
|
|
|
31 |
|
32 |
return user_uuid, token
|
33 |
|
@@ -126,17 +127,18 @@ def log(level, info_text):
|
|
126 |
print(f"[ {level} ] - {time.strftime('%Y%m%d_%H:%M:%S', time.localtime())} - {info_text}")
|
127 |
|
128 |
class Generator:
|
129 |
-
def __init__(self, user_id, password) -> None:
|
130 |
-
_, self.token = login(user_id, password)
|
|
|
131 |
self.user_id = user_id
|
132 |
self.password = password
|
133 |
self.task_uuid = None
|
134 |
self.processed_image = None
|
135 |
|
136 |
-
def preprocess(self, prompt, image_path, task_uuid=""):
|
137 |
-
if prompt and task_uuid != "":
|
138 |
log("INFO", "Using cached image and prompt...")
|
139 |
-
return prompt
|
140 |
log("INFO", "Preprocessing image...")
|
141 |
success = False
|
142 |
while not success:
|
@@ -158,19 +160,19 @@ class Generator:
|
|
158 |
try:
|
159 |
if not (prompt and task_uuid):
|
160 |
prompt = preprocess_response.get('prompt', None)
|
161 |
-
|
162 |
success = True
|
163 |
except Exception as e:
|
164 |
log("ERROR", f"Error in image preprocessing: {preprocess_response}")
|
165 |
raise e
|
166 |
|
167 |
-
return prompt
|
168 |
|
169 |
-
def generate_mesh(self, prompt, task_uuid=""):
|
170 |
log("INFO", "Generating mesh...")
|
171 |
if task_uuid == "":
|
172 |
settings = {'view_weights': [1]} # Define weights as per your requirements, for multiple images, use multiple values, e,g [0.5, 0.5]
|
173 |
-
images = [
|
174 |
|
175 |
mesh_response = rodin_mesh(prompt=prompt, group_uuid=None, settings=settings, images=images, name="images.jpeg", token=self.token)
|
176 |
progress_checker = JobStatusChecker(BASE_URL, mesh_response['job']['subscription_key'])
|
@@ -199,6 +201,7 @@ class Generator:
|
|
199 |
except Exception as e:
|
200 |
log("ERROR", f"Error in updating mesh: {e}")
|
201 |
time.sleep(5)
|
|
|
202 |
history = rodin_history(task_uuid, self.token)
|
203 |
try:
|
204 |
preview_image = next(reversed(history.items()))[1]["preview_image"]
|
|
|
28 |
log("INFO", f"Logged successfully")
|
29 |
user_uuid = response_data['user_uuid']
|
30 |
token = response_data['token']
|
31 |
+
print(user_uuid, token)
|
32 |
|
33 |
return user_uuid, token
|
34 |
|
|
|
127 |
print(f"[ {level} ] - {time.strftime('%Y%m%d_%H:%M:%S', time.localtime())} - {info_text}")
|
128 |
|
129 |
class Generator:
|
130 |
+
def __init__(self, user_id, password, token) -> None:
|
131 |
+
# _, self.token = login(user_id, password)
|
132 |
+
self.token = token
|
133 |
self.user_id = user_id
|
134 |
self.password = password
|
135 |
self.task_uuid = None
|
136 |
self.processed_image = None
|
137 |
|
138 |
+
def preprocess(self, prompt, image_path, processed_image , task_uuid=""):
|
139 |
+
if processed_image and prompt and task_uuid != "":
|
140 |
log("INFO", "Using cached image and prompt...")
|
141 |
+
return prompt, processed_image
|
142 |
log("INFO", "Preprocessing image...")
|
143 |
success = False
|
144 |
while not success:
|
|
|
160 |
try:
|
161 |
if not (prompt and task_uuid):
|
162 |
prompt = preprocess_response.get('prompt', None)
|
163 |
+
processed_image = "data:image/png;base64," + preprocess_response.get('processed_image', None)
|
164 |
success = True
|
165 |
except Exception as e:
|
166 |
log("ERROR", f"Error in image preprocessing: {preprocess_response}")
|
167 |
raise e
|
168 |
|
169 |
+
return prompt, processed_image
|
170 |
|
171 |
+
def generate_mesh(self, prompt, processed_image, task_uuid=""):
|
172 |
log("INFO", "Generating mesh...")
|
173 |
if task_uuid == "":
|
174 |
settings = {'view_weights': [1]} # Define weights as per your requirements, for multiple images, use multiple values, e,g [0.5, 0.5]
|
175 |
+
images = [processed_image] # List of images, all the images should be processed first
|
176 |
|
177 |
mesh_response = rodin_mesh(prompt=prompt, group_uuid=None, settings=settings, images=images, name="images.jpeg", token=self.token)
|
178 |
progress_checker = JobStatusChecker(BASE_URL, mesh_response['job']['subscription_key'])
|
|
|
201 |
except Exception as e:
|
202 |
log("ERROR", f"Error in updating mesh: {e}")
|
203 |
time.sleep(5)
|
204 |
+
|
205 |
history = rodin_history(task_uuid, self.token)
|
206 |
try:
|
207 |
preview_image = next(reversed(history.items()))[1]["preview_image"]
|
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import os
|
2 |
-
os.system('pip uninstall -y gradio_fake3d')
|
3 |
-
os.system('pip install gradio_fake3d-0.0.3-py3-none-any.whl')
|
4 |
|
5 |
import gradio as gr
|
6 |
import re
|
@@ -9,7 +9,7 @@ from PIL import Image
|
|
9 |
from Rodin import Generator, crop_image
|
10 |
from constant import *
|
11 |
|
12 |
-
generator = Generator(USER, PASSWORD)
|
13 |
|
14 |
change_button_name = """
|
15 |
function updateButton(input) {
|
@@ -19,6 +19,14 @@ function updateButton(input) {
|
|
19 |
}
|
20 |
"""
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
reset_button_name = """
|
23 |
function updateButton(input) {
|
24 |
var buttonGenerate = document.getElementById('button_generate');
|
@@ -52,6 +60,19 @@ options = [
|
|
52 |
"OpenClay(200M) - Coming soon"
|
53 |
]
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
def do_nothing(text):
|
56 |
return ""
|
57 |
|
@@ -88,6 +109,9 @@ def handle_prompt_change(prompt):
|
|
88 |
def clear_task():
|
89 |
return "", "", [], None
|
90 |
|
|
|
|
|
|
|
91 |
def return_render(image):
|
92 |
image = Image.fromarray(image)
|
93 |
return image, crop_image(image, DEFAULT)
|
@@ -118,7 +142,7 @@ with gr.Blocks() as demo:
|
|
118 |
show_label=True,
|
119 |
label="Prompt",
|
120 |
)
|
121 |
-
block_prompt_hint = gr.CheckboxGroup(value="Labels", choices=PROMPT_HINT_LIST)
|
122 |
|
123 |
with gr.Column():
|
124 |
with gr.Group():
|
@@ -135,25 +159,33 @@ with gr.Blocks() as demo:
|
|
135 |
block_normal = gr.Button("Normal", min_width=0)
|
136 |
|
137 |
button_more = gr.Button(value="Download", variant="primary", link=rodin_url)
|
138 |
-
|
139 |
cache_raw_image = gr.Image(visible=False, type="pil")
|
140 |
cacha_empty = gr.Text(visible=False)
|
|
|
141 |
cache_task_uuid = gr.Text(value="", visible=False)
|
|
|
|
|
142 |
|
143 |
block_image.upload(
|
144 |
fn=do_nothing,
|
145 |
-
js=
|
146 |
inputs=[cacha_empty],
|
147 |
outputs=[cacha_empty]
|
148 |
).success(
|
149 |
fn=generator.preprocess,
|
150 |
-
inputs=[block_prompt, block_image, cache_task_uuid],
|
151 |
-
outputs=[block_prompt],
|
152 |
show_progress="minimal"
|
153 |
).success(
|
154 |
fn=generator.generate_mesh,
|
155 |
-
inputs=[block_prompt, cache_task_uuid],
|
156 |
outputs=[cache_raw_image, cache_task_uuid, fake3d],
|
|
|
|
|
|
|
|
|
|
|
157 |
)
|
158 |
|
159 |
block_image.clear(
|
@@ -163,15 +195,32 @@ with gr.Blocks() as demo:
|
|
163 |
outputs=[cacha_empty]
|
164 |
).then(fn=clear_task, outputs=[cache_task_uuid, block_prompt, block_prompt_hint, fake3d], show_progress="hidden")
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
button_generate.click(
|
|
|
|
|
|
|
|
|
|
|
167 |
fn=generator.preprocess,
|
168 |
-
inputs=[block_prompt, block_image, cache_task_uuid],
|
169 |
-
outputs=[block_prompt],
|
170 |
show_progress="minimal"
|
171 |
).success(
|
172 |
fn=generator.generate_mesh,
|
173 |
-
inputs=[block_prompt, cache_task_uuid],
|
174 |
outputs=[cache_raw_image, cache_task_uuid, fake3d],
|
|
|
|
|
|
|
|
|
|
|
175 |
)
|
176 |
|
177 |
block_default.click(fn=crop_image_default, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|
|
|
1 |
import os
|
2 |
+
# os.system('pip uninstall -y gradio_fake3d')
|
3 |
+
# os.system('pip install gradio_fake3d-0.0.3-py3-none-any.whl')
|
4 |
|
5 |
import gradio as gr
|
6 |
import re
|
|
|
9 |
from Rodin import Generator, crop_image
|
10 |
from constant import *
|
11 |
|
12 |
+
generator = Generator(USER, PASSWORD, TOKEN)
|
13 |
|
14 |
change_button_name = """
|
15 |
function updateButton(input) {
|
|
|
19 |
}
|
20 |
"""
|
21 |
|
22 |
+
change_button_name_to_generating = """
|
23 |
+
function updateButton(input) {
|
24 |
+
var buttonGenerate = document.getElementById('button_generate');
|
25 |
+
buttonGenerate.innerText = 'Generating...';
|
26 |
+
return '';
|
27 |
+
}
|
28 |
+
"""
|
29 |
+
|
30 |
reset_button_name = """
|
31 |
function updateButton(input) {
|
32 |
var buttonGenerate = document.getElementById('button_generate');
|
|
|
60 |
"OpenClay(200M) - Coming soon"
|
61 |
]
|
62 |
|
63 |
+
example = [
|
64 |
+
["assets/00.png", "Creature with adorable and grumpy face, cartoon style. symmetric geometry. character. smooth edges. simple geometry."],
|
65 |
+
["assets/07.png", "Retro-styled robot with minimalistic design, glowing eyes. symmetric geometry. character. smooth edges. simple geometry. game-ready."],
|
66 |
+
["assets/08.png", ""],
|
67 |
+
["assets/11.png", ""],
|
68 |
+
["assets/13.png", ""],
|
69 |
+
["assets/21.png", ""],
|
70 |
+
["assets/24.PNG", "Dragon-like cartoon character with small wings and antennae. symmetric geometry. character. smooth edges.", ],
|
71 |
+
["assets/30.png", ""],
|
72 |
+
["assets/42.png", ""],
|
73 |
+
["assets/46.png", ""]
|
74 |
+
]
|
75 |
+
|
76 |
def do_nothing(text):
|
77 |
return ""
|
78 |
|
|
|
109 |
def clear_task():
|
110 |
return "", "", [], None
|
111 |
|
112 |
+
def clear_task_id():
|
113 |
+
return ""
|
114 |
+
|
115 |
def return_render(image):
|
116 |
image = Image.fromarray(image)
|
117 |
return image, crop_image(image, DEFAULT)
|
|
|
142 |
show_label=True,
|
143 |
label="Prompt",
|
144 |
)
|
145 |
+
block_prompt_hint = gr.CheckboxGroup(value="Labels", choices=PROMPT_HINT_LIST, show_label=False)
|
146 |
|
147 |
with gr.Column():
|
148 |
with gr.Group():
|
|
|
159 |
block_normal = gr.Button("Normal", min_width=0)
|
160 |
|
161 |
button_more = gr.Button(value="Download", variant="primary", link=rodin_url)
|
162 |
+
|
163 |
cache_raw_image = gr.Image(visible=False, type="pil")
|
164 |
cacha_empty = gr.Text(visible=False)
|
165 |
+
cache_image_base64 = gr.Text(visible=False)
|
166 |
cache_task_uuid = gr.Text(value="", visible=False)
|
167 |
+
|
168 |
+
# block_example = gr.Examples(examples=example ,inputs=[block_image, block_prompt], outputs=[fake3d], label="Examples")
|
169 |
|
170 |
block_image.upload(
|
171 |
fn=do_nothing,
|
172 |
+
js=change_button_name_to_generating,
|
173 |
inputs=[cacha_empty],
|
174 |
outputs=[cacha_empty]
|
175 |
).success(
|
176 |
fn=generator.preprocess,
|
177 |
+
inputs=[block_prompt, block_image, cache_image_base64, cache_task_uuid],
|
178 |
+
outputs=[block_prompt, cache_image_base64],
|
179 |
show_progress="minimal"
|
180 |
).success(
|
181 |
fn=generator.generate_mesh,
|
182 |
+
inputs=[block_prompt, cache_image_base64, cache_task_uuid],
|
183 |
outputs=[cache_raw_image, cache_task_uuid, fake3d],
|
184 |
+
).success(
|
185 |
+
fn=do_nothing,
|
186 |
+
js=change_button_name,
|
187 |
+
inputs=[cacha_empty],
|
188 |
+
outputs=[cacha_empty]
|
189 |
)
|
190 |
|
191 |
block_image.clear(
|
|
|
195 |
outputs=[cacha_empty]
|
196 |
).then(fn=clear_task, outputs=[cache_task_uuid, block_prompt, block_prompt_hint, fake3d], show_progress="hidden")
|
197 |
|
198 |
+
# block_image.change(
|
199 |
+
# fn=do_nothing,
|
200 |
+
# js=reset_button_name,
|
201 |
+
# inputs=[cacha_empty],
|
202 |
+
# outputs=[cacha_empty]
|
203 |
+
# ).then(fn=clear_task_id, outputs=[cache_task_uuid], show_progress="hidden")
|
204 |
+
|
205 |
button_generate.click(
|
206 |
+
fn=do_nothing,
|
207 |
+
js=change_button_name_to_generating,
|
208 |
+
inputs=[cacha_empty],
|
209 |
+
outputs=[cacha_empty]
|
210 |
+
).success(
|
211 |
fn=generator.preprocess,
|
212 |
+
inputs=[block_prompt, block_image, cache_image_base64, cache_task_uuid],
|
213 |
+
outputs=[block_prompt, cache_image_base64],
|
214 |
show_progress="minimal"
|
215 |
).success(
|
216 |
fn=generator.generate_mesh,
|
217 |
+
inputs=[block_prompt, cache_image_base64, cache_task_uuid],
|
218 |
outputs=[cache_raw_image, cache_task_uuid, fake3d],
|
219 |
+
).then(
|
220 |
+
fn=do_nothing,
|
221 |
+
js=change_button_name,
|
222 |
+
inputs=[cacha_empty],
|
223 |
+
outputs=[cacha_empty]
|
224 |
)
|
225 |
|
226 |
block_default.click(fn=crop_image_default, inputs=[cache_raw_image], outputs=fake3d, show_progress="minimal")
|
assets/00.png
ADDED
assets/07.png
ADDED
assets/08.png
ADDED
assets/11.png
ADDED
assets/13.png
ADDED
assets/21.png
ADDED
assets/24.PNG
ADDED
assets/30.png
ADDED
assets/42.png
ADDED
assets/46.png
ADDED
constant.py
CHANGED
@@ -6,6 +6,7 @@ BASE_URL = os.getenv("BASE_URL")
|
|
6 |
# Creds
|
7 |
USER = os.getenv("USER")
|
8 |
PASSWORD = os.getenv("PASSWORD")
|
|
|
9 |
|
10 |
DEFAULT = [0, 0]
|
11 |
CONTRAST = [360, 0]
|
|
|
6 |
# Creds
|
7 |
USER = os.getenv("USER")
|
8 |
PASSWORD = os.getenv("PASSWORD")
|
9 |
+
TOKEN = os.getenv("TOKEN")
|
10 |
|
11 |
DEFAULT = [0, 0]
|
12 |
CONTRAST = [360, 0]
|