Spaces:
Runtime error
Runtime error
Update app_gradio.py
Browse files- app_gradio.py +74 -52
app_gradio.py
CHANGED
|
@@ -222,11 +222,12 @@ def create_gradio_interface():
|
|
| 222 |
|
| 223 |
"""
|
| 224 |
)
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
|
| 229 |
-
with gr.Tab("Main") as main_tab:
|
| 230 |
input_sketch = gr.Image(
|
| 231 |
type="pil",
|
| 232 |
label="Selected Sketch",
|
|
@@ -234,41 +235,13 @@ def create_gradio_interface():
|
|
| 234 |
interactive=True,
|
| 235 |
height=300 # Fixed height for consistency
|
| 236 |
)
|
| 237 |
-
|
| 238 |
-
"
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
interactive=True,
|
| 242 |
)
|
| 243 |
|
| 244 |
-
with gr.Tab("Draw"):
|
| 245 |
-
draw_sketchpad = gr.Sketchpad(
|
| 246 |
-
value={
|
| 247 |
-
"background": "./static/examples/background.jpeg",
|
| 248 |
-
"layers": None,
|
| 249 |
-
"composite": None
|
| 250 |
-
},
|
| 251 |
-
type="pil",
|
| 252 |
-
image_mode="RGB",
|
| 253 |
-
layers=False,
|
| 254 |
-
|
| 255 |
-
)
|
| 256 |
-
sketchpad_generate_btn = gr.Button(
|
| 257 |
-
"Generate Animation",
|
| 258 |
-
variant="primary",
|
| 259 |
-
elem_classes="generate-btn",
|
| 260 |
-
interactive=True,
|
| 261 |
-
)
|
| 262 |
-
|
| 263 |
|
| 264 |
-
|
| 265 |
-
motion_prompt = gr.Textbox(
|
| 266 |
-
label="Prompt",
|
| 267 |
-
placeholder="Describe the motion...",
|
| 268 |
-
lines=3
|
| 269 |
-
)
|
| 270 |
-
|
| 271 |
-
with gr.Row():
|
| 272 |
num_seeds = gr.Slider(
|
| 273 |
minimum=1,
|
| 274 |
maximum=10,
|
|
@@ -282,15 +255,10 @@ def create_gradio_interface():
|
|
| 282 |
value=0.5,
|
| 283 |
step=0.1,
|
| 284 |
label="Motion Strength"
|
| 285 |
-
)
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
with gr.Column():
|
| 290 |
-
def load_examples(input_sketch, motion_prompt):
|
| 291 |
-
return gr.update(open=True)
|
| 292 |
-
|
| 293 |
-
gr.Examples(
|
| 294 |
examples=[
|
| 295 |
['./static/examples/sketch1.png', 'The camel walks slowly'],
|
| 296 |
['./static/examples/sketch2.png', 'The wine in the wine glass sways from side to side'],
|
|
@@ -305,14 +273,54 @@ def create_gradio_interface():
|
|
| 305 |
['./static/examples/sketch11.png', 'The jazz saxophonist performs on stage with a rhythmic sway, his upper body sways subtly to the rhythm of the music.'],
|
| 306 |
['./static/examples/sketch12.png', 'The biker rides on the road']
|
| 307 |
],
|
| 308 |
-
fn=load_examples,
|
| 309 |
inputs=[input_sketch, motion_prompt],
|
| 310 |
-
|
| 311 |
-
examples_per_page=4,
|
| 312 |
-
cache_examples=False
|
| 313 |
-
|
| 314 |
)
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
output_gallery = gr.Gallery(
|
| 318 |
label="Results",
|
|
@@ -339,13 +347,27 @@ def create_gradio_interface():
|
|
| 339 |
],
|
| 340 |
outputs=output_gallery
|
| 341 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
sketchpad_generate_btn.click(
|
| 343 |
fn=generate_output_from_sketchpad,
|
| 344 |
inputs=[
|
| 345 |
draw_sketchpad,
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
],
|
| 350 |
outputs=output_gallery
|
| 351 |
)
|
|
|
|
| 222 |
|
| 223 |
"""
|
| 224 |
)
|
| 225 |
+
|
| 226 |
+
with gr.Tab("Main"):
|
| 227 |
|
| 228 |
+
with gr.Row():
|
| 229 |
+
with gr.Column():
|
| 230 |
|
|
|
|
| 231 |
input_sketch = gr.Image(
|
| 232 |
type="pil",
|
| 233 |
label="Selected Sketch",
|
|
|
|
| 235 |
interactive=True,
|
| 236 |
height=300 # Fixed height for consistency
|
| 237 |
)
|
| 238 |
+
motion_prompt = gr.Textbox(
|
| 239 |
+
label="Prompt",
|
| 240 |
+
placeholder="Describe the motion...",
|
| 241 |
+
lines=3
|
|
|
|
| 242 |
)
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
num_seeds = gr.Slider(
|
| 246 |
minimum=1,
|
| 247 |
maximum=10,
|
|
|
|
| 255 |
value=0.5,
|
| 256 |
step=0.1,
|
| 257 |
label="Motion Strength"
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
with gr.Column():
|
| 261 |
+
gr.Examples(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
examples=[
|
| 263 |
['./static/examples/sketch1.png', 'The camel walks slowly'],
|
| 264 |
['./static/examples/sketch2.png', 'The wine in the wine glass sways from side to side'],
|
|
|
|
| 273 |
['./static/examples/sketch11.png', 'The jazz saxophonist performs on stage with a rhythmic sway, his upper body sways subtly to the rhythm of the music.'],
|
| 274 |
['./static/examples/sketch12.png', 'The biker rides on the road']
|
| 275 |
],
|
|
|
|
| 276 |
inputs=[input_sketch, motion_prompt],
|
| 277 |
+
examples_per_page=4,
|
|
|
|
|
|
|
|
|
|
| 278 |
)
|
| 279 |
|
| 280 |
+
with gr.Tab("Draw"):
|
| 281 |
+
with gr.Row():
|
| 282 |
+
with gr.Column():
|
| 283 |
+
draw_sketchpad = gr.Sketchpad(
|
| 284 |
+
value={
|
| 285 |
+
"background": "./static/examples/background.jpeg",
|
| 286 |
+
"layers": None,
|
| 287 |
+
"composite": None
|
| 288 |
+
},
|
| 289 |
+
type="pil",
|
| 290 |
+
image_mode="RGB",
|
| 291 |
+
layers=False,
|
| 292 |
+
|
| 293 |
+
)
|
| 294 |
+
with gr.Column():
|
| 295 |
+
draw_motion_prompt = gr.Textbox(
|
| 296 |
+
label="Prompt",
|
| 297 |
+
placeholder="Describe the motion...",
|
| 298 |
+
lines=3
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
draw_num_seeds = gr.Slider(
|
| 303 |
+
minimum=1,
|
| 304 |
+
maximum=10,
|
| 305 |
+
value=5,
|
| 306 |
+
step=1,
|
| 307 |
+
label="Seeds"
|
| 308 |
+
)
|
| 309 |
+
draw_lambda_ = gr.Slider(
|
| 310 |
+
minimum=0,
|
| 311 |
+
maximum=1,
|
| 312 |
+
value=0.5,
|
| 313 |
+
step=0.1,
|
| 314 |
+
label="Motion Strength"
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
sketchpad_generate_btn = gr.Button(
|
| 318 |
+
"Generate Animation",
|
| 319 |
+
variant="primary",
|
| 320 |
+
elem_classes="generate-btn",
|
| 321 |
+
interactive=True,
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
|
| 325 |
output_gallery = gr.Gallery(
|
| 326 |
label="Results",
|
|
|
|
| 347 |
],
|
| 348 |
outputs=output_gallery
|
| 349 |
)
|
| 350 |
+
def reload_pad():
|
| 351 |
+
blank_pad ={
|
| 352 |
+
"background": "./static/examples/background.jpeg",
|
| 353 |
+
"layers": None,
|
| 354 |
+
"composite": None
|
| 355 |
+
}
|
| 356 |
+
return blank_pad
|
| 357 |
+
|
| 358 |
+
draw_sketchpad.delete(
|
| 359 |
+
fn=reload_pad,
|
| 360 |
+
inputs = None,
|
| 361 |
+
outputs = [draw_sketchpad],
|
| 362 |
+
queue=False
|
| 363 |
+
)
|
| 364 |
sketchpad_generate_btn.click(
|
| 365 |
fn=generate_output_from_sketchpad,
|
| 366 |
inputs=[
|
| 367 |
draw_sketchpad,
|
| 368 |
+
draw_motion_prompt,
|
| 369 |
+
draw_num_seeds,
|
| 370 |
+
draw_lambda_
|
| 371 |
],
|
| 372 |
outputs=output_gallery
|
| 373 |
)
|