Spaces:
Sleeping
Sleeping
Anonymous
commited on
Commit
•
11ba8fa
1
Parent(s):
4dd34ca
add example
Browse files
app.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
import sys
|
2 |
-
import gradio as gr
|
3 |
import random
|
4 |
-
import
|
5 |
-
import numpy as np
|
6 |
import matplotlib.pyplot as plt
|
7 |
|
8 |
import os
|
@@ -454,10 +452,10 @@ def demo_update_h(mode):
|
|
454 |
h_positions.append(gr.Slider(value=0.9))
|
455 |
elif mode == 'left->right->left->right':
|
456 |
num = 4
|
457 |
-
h_positions.append(gr.Slider(value=0.
|
458 |
-
h_positions.append(gr.Slider(value=0.
|
459 |
-
h_positions.append(gr.Slider(value=0.
|
460 |
-
h_positions.append(gr.Slider(value=0.
|
461 |
elif mode == 'triangle':
|
462 |
num = 4
|
463 |
h_positions.append(gr.Slider(value=0.1))
|
@@ -505,10 +503,10 @@ def demo_update_w(mode):
|
|
505 |
w_positions.append(gr.Slider(value=0.1))
|
506 |
elif mode == 'left->right->left->right':
|
507 |
num = 4
|
508 |
-
w_positions.append(gr.Slider(value=0.
|
509 |
-
w_positions.append(gr.Slider(value=0.
|
510 |
-
w_positions.append(gr.Slider(value=0.
|
511 |
-
w_positions.append(gr.Slider(value=0.
|
512 |
elif mode == 'triangle':
|
513 |
num = 4
|
514 |
w_positions.append(gr.Slider(value=0.5))
|
@@ -523,13 +521,13 @@ def demo_update_w(mode):
|
|
523 |
return w_positions
|
524 |
|
525 |
def plot_update(*positions):
|
526 |
-
|
|
|
|
|
527 |
traj_plot = gr.Plot(
|
528 |
label="Trajectory"
|
529 |
)
|
530 |
return traj_plot
|
531 |
-
key_length = positions[-1]
|
532 |
-
frame_indices = positions[:key_length]
|
533 |
frame_indices = [int(i) for i in frame_indices]
|
534 |
h_positions = positions[MAX_KEYS:MAX_KEYS+key_length]
|
535 |
w_positions = positions[2*MAX_KEYS:2*MAX_KEYS+key_length]
|
@@ -606,25 +604,29 @@ with gr.Blocks(css=css) as demo:
|
|
606 |
|
607 |
for i in range(MAX_KEYS):
|
608 |
with gr.Row(visible=False) as row:
|
609 |
-
text =
|
610 |
-
|
|
|
|
|
|
|
|
|
|
|
611 |
frame_ids = gr.Textbox(
|
612 |
None,
|
613 |
label=f"Frame Indices #{i}",
|
614 |
-
visible=True,
|
615 |
interactive=True,
|
616 |
-
scale=
|
617 |
)
|
618 |
h_position = gr.Slider(label='Position in Height',
|
619 |
minimum=0.0,
|
620 |
maximum=1.0,
|
621 |
step=0.01,
|
622 |
-
scale=
|
623 |
w_position = gr.Slider(label='Position in Width',
|
624 |
minimum=0.0,
|
625 |
maximum=1.0,
|
626 |
step=0.01,
|
627 |
-
scale=
|
628 |
|
629 |
frame_indices.append(frame_ids)
|
630 |
h_positions.append(h_position)
|
|
|
1 |
import sys
|
|
|
2 |
import random
|
3 |
+
import gradio as gr
|
|
|
4 |
import matplotlib.pyplot as plt
|
5 |
|
6 |
import os
|
|
|
452 |
h_positions.append(gr.Slider(value=0.9))
|
453 |
elif mode == 'left->right->left->right':
|
454 |
num = 4
|
455 |
+
h_positions.append(gr.Slider(value=0.5))
|
456 |
+
h_positions.append(gr.Slider(value=0.5))
|
457 |
+
h_positions.append(gr.Slider(value=0.5))
|
458 |
+
h_positions.append(gr.Slider(value=0.5))
|
459 |
elif mode == 'triangle':
|
460 |
num = 4
|
461 |
h_positions.append(gr.Slider(value=0.1))
|
|
|
503 |
w_positions.append(gr.Slider(value=0.1))
|
504 |
elif mode == 'left->right->left->right':
|
505 |
num = 4
|
506 |
+
w_positions.append(gr.Slider(value=0.1))
|
507 |
+
w_positions.append(gr.Slider(value=0.9))
|
508 |
+
w_positions.append(gr.Slider(value=0.1))
|
509 |
+
w_positions.append(gr.Slider(value=0.9))
|
510 |
elif mode == 'triangle':
|
511 |
num = 4
|
512 |
w_positions.append(gr.Slider(value=0.5))
|
|
|
521 |
return w_positions
|
522 |
|
523 |
def plot_update(*positions):
|
524 |
+
key_length = positions[-1]
|
525 |
+
frame_indices = positions[:key_length]
|
526 |
+
if type(key_length) != int or len(frame_indices) < 2:
|
527 |
traj_plot = gr.Plot(
|
528 |
label="Trajectory"
|
529 |
)
|
530 |
return traj_plot
|
|
|
|
|
531 |
frame_indices = [int(i) for i in frame_indices]
|
532 |
h_positions = positions[MAX_KEYS:MAX_KEYS+key_length]
|
533 |
w_positions = positions[2*MAX_KEYS:2*MAX_KEYS+key_length]
|
|
|
604 |
|
605 |
for i in range(MAX_KEYS):
|
606 |
with gr.Row(visible=False) as row:
|
607 |
+
text = gr.Textbox(
|
608 |
+
value=f"Keyframe #{i}",
|
609 |
+
interactive=False,
|
610 |
+
container = False,
|
611 |
+
lines = 3,
|
612 |
+
scale=1
|
613 |
+
)
|
614 |
frame_ids = gr.Textbox(
|
615 |
None,
|
616 |
label=f"Frame Indices #{i}",
|
|
|
617 |
interactive=True,
|
618 |
+
scale=2
|
619 |
)
|
620 |
h_position = gr.Slider(label='Position in Height',
|
621 |
minimum=0.0,
|
622 |
maximum=1.0,
|
623 |
step=0.01,
|
624 |
+
scale=2)
|
625 |
w_position = gr.Slider(label='Position in Width',
|
626 |
minimum=0.0,
|
627 |
maximum=1.0,
|
628 |
step=0.01,
|
629 |
+
scale=2)
|
630 |
|
631 |
frame_indices.append(frame_ids)
|
632 |
h_positions.append(h_position)
|