Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,7 +93,15 @@ def get_sampler(model_name, txt2obj, guidance_scale):
|
|
| 93 |
model_kwargs_key_filter=('texts', '') if txt2obj else ("*",)
|
| 94 |
)
|
| 95 |
|
| 96 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
set_state('Entered generate function...')
|
| 99 |
|
|
@@ -186,6 +194,12 @@ with gr.Blocks() as app:
|
|
| 186 |
img = gr.Image(label="Image")
|
| 187 |
gr.Markdown("Best results with images of 3D objects with no shadows on a white background.")
|
| 188 |
btn_generate_img2obj = gr.Button(value="Generate")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
with gr.Accordion("Advanced settings", open=False):
|
| 191 |
dropdown_models = gr.Dropdown(label="Model", value="base40M", choices=["base40M"]) #, "base300M", "base1B"])
|
|
@@ -198,15 +212,20 @@ with gr.Blocks() as app:
|
|
| 198 |
model_3d = gr.Model3D(value=None)
|
| 199 |
file_out = gr.File(label="Obj file", visible=False)
|
| 200 |
|
| 201 |
-
state_info = state_info = gr.Textbox(label="State", show_label=False).style(container=False)
|
| 202 |
|
| 203 |
|
| 204 |
# inputs = [dropdown_models, prompt, img, guidance_scale, grid_size]
|
| 205 |
outputs = [plot, model_3d, file_out]
|
| 206 |
|
| 207 |
-
prompt.submit(
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
# btn_pc_to_obj.click(ply_to_obj, inputs=plot, outputs=[model_3d, file_out])
|
| 211 |
|
| 212 |
gr.HTML("""
|
|
@@ -231,8 +250,8 @@ with gr.Blocks() as app:
|
|
| 231 |
["a man"],
|
| 232 |
],
|
| 233 |
inputs=[prompt],
|
| 234 |
-
fn=
|
| 235 |
-
cache_examples=
|
| 236 |
)
|
| 237 |
|
| 238 |
gr.Examples(
|
|
@@ -242,8 +261,8 @@ with gr.Blocks() as app:
|
|
| 242 |
["chair.png"],
|
| 243 |
],
|
| 244 |
inputs=[img],
|
| 245 |
-
fn=
|
| 246 |
-
cache_examples=
|
| 247 |
)
|
| 248 |
|
| 249 |
# app.load(get_state, inputs=[], outputs=state_info, every=0.5, show_progress=False)
|
|
|
|
| 93 |
model_kwargs_key_filter=('texts', '') if txt2obj else ("*",)
|
| 94 |
)
|
| 95 |
|
| 96 |
+
def generate_txt2sd(prompt):
|
| 97 |
+
prompt = f"βa 3d rendering of {prompt}, chair imitating an avocado, full view, white background"
|
| 98 |
+
stable_diffusion = gr.Blocks.load(name="spaces/runwayml/stable-diffusion-v1-5")
|
| 99 |
+
image = stable_diffusion(prompt, fn_index=2)[0]
|
| 100 |
+
|
| 101 |
+
return image, gr.update(visible=True)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def generate_3D(input, model_name='base40M', guidance_scale=3.0, grid_size=32):
|
| 105 |
|
| 106 |
set_state('Entered generate function...')
|
| 107 |
|
|
|
|
| 194 |
img = gr.Image(label="Image")
|
| 195 |
gr.Markdown("Best results with images of 3D objects with no shadows on a white background.")
|
| 196 |
btn_generate_img2obj = gr.Button(value="Generate")
|
| 197 |
+
with gr.Tab("Text to SD to 3D"):
|
| 198 |
+
gr.Markdown("Generate an image with Stable Diffusion, then convert to 3D. Just enter the object you want to generate.")
|
| 199 |
+
prompt_sd = gr.Textbox(label="Prompt", placeholder="a 3d rendering of [your prompt], full view, white background")
|
| 200 |
+
btn_generate_txt2sd = gr.Button(value="Generate")
|
| 201 |
+
img_sd = gr.Image(label="Image", visible=False)
|
| 202 |
+
btn_generate_sd2obj = gr.Button(value="Convert to 3D", visible=False)
|
| 203 |
|
| 204 |
with gr.Accordion("Advanced settings", open=False):
|
| 205 |
dropdown_models = gr.Dropdown(label="Model", value="base40M", choices=["base40M"]) #, "base300M", "base1B"])
|
|
|
|
| 212 |
model_3d = gr.Model3D(value=None)
|
| 213 |
file_out = gr.File(label="Obj file", visible=False)
|
| 214 |
|
| 215 |
+
# state_info = state_info = gr.Textbox(label="State", show_label=False).style(container=False)
|
| 216 |
|
| 217 |
|
| 218 |
# inputs = [dropdown_models, prompt, img, guidance_scale, grid_size]
|
| 219 |
outputs = [plot, model_3d, file_out]
|
| 220 |
|
| 221 |
+
prompt.submit(generate_3D, inputs=[prompt, dropdown_models, guidance_scale, grid_size], outputs=outputs)
|
| 222 |
+
|
| 223 |
+
btn_generate_txt2obj.click(generate_3D, inputs=[prompt, dropdown_models, guidance_scale, grid_size], outputs=outputs)
|
| 224 |
+
btn_generate_img2obj.click(generate_3D, inputs=[img, dropdown_models, guidance_scale, grid_size], outputs=outputs)
|
| 225 |
+
|
| 226 |
+
btn_generate_txt2sd.click(generate_txt2sd, inputs=prompt_sd, outputs=[img_sd, btn_generate_sd2obj])
|
| 227 |
+
btn_generate_sd2obj.click(generate_3D, inputs=[img, dropdown_models, guidance_scale, grid_size], outputs=outputs)
|
| 228 |
+
|
| 229 |
# btn_pc_to_obj.click(ply_to_obj, inputs=plot, outputs=[model_3d, file_out])
|
| 230 |
|
| 231 |
gr.HTML("""
|
|
|
|
| 250 |
["a man"],
|
| 251 |
],
|
| 252 |
inputs=[prompt],
|
| 253 |
+
fn=generate_3D,
|
| 254 |
+
cache_examples=False
|
| 255 |
)
|
| 256 |
|
| 257 |
gr.Examples(
|
|
|
|
| 261 |
["chair.png"],
|
| 262 |
],
|
| 263 |
inputs=[img],
|
| 264 |
+
fn=generate_3D,
|
| 265 |
+
cache_examples=False
|
| 266 |
)
|
| 267 |
|
| 268 |
# app.load(get_state, inputs=[], outputs=state_info, every=0.5, show_progress=False)
|