Spaces:
Running
Running
import gradio as gr | |
from main_func import video_identity | |
with gr.Blocks() as demo: | |
with gr.Row(variant='compact'): | |
with gr.Column(): | |
gr.Markdown("#### Dynamic Time Warping:") | |
with gr.Row(variant='compact'): | |
dtw_mean = gr.Slider( | |
value=0.4, | |
minimum=0, | |
maximum=1.0, | |
step=0.05, | |
label="Winsorized Mean" | |
) | |
dtw_filter = gr.Slider( | |
value=13, | |
minimum=1, | |
maximum=20, | |
step=1, | |
label="Savitzky-Golay Filter" | |
) | |
gr.Markdown("#### Thresholds:") | |
with gr.Row(variant='compact'): | |
angles_sensitive = gr.Number( | |
value=15, | |
minimum=0, | |
maximum=75, | |
step=1, | |
min_width=100, | |
label="Sensitive" | |
) | |
angles_common = gr.Number( | |
value=30, | |
minimum=0, | |
maximum=75, | |
step=1, | |
min_width=100, | |
label="Standart" | |
) | |
angles_insensitive = gr.Number( | |
value=55, | |
minimum=0, | |
maximum=75, | |
step=1, | |
min_width=100, | |
label="Insensitive" | |
) | |
gr.Markdown("#### Patience:") | |
trigger_state = gr.Radio(value="one", choices=["one", "two", "three"], label="Trigger Count") | |
gr.Markdown("#### Plot arrows:") | |
show_arrows = gr.Checkbox(label="If True, arrows will be plotted on the video") | |
input_teacher = gr.Video(show_share_button=False, show_download_button=False, sources=["upload"], label="Teacher's Video") | |
input_student = gr.Video(show_share_button=False, show_download_button=False, sources=["upload"], label="Student's Video") | |
with gr.Accordion("Usage:", open=False): | |
with gr.Accordion("Application purpose:", open=False): | |
gr.Markdown(""" | |
This application is designed to compare a professional dancer's performance with that of a student, identifying the student's incorrect movements relative to the professional. | |
Key features: | |
1. Accepts two dance videos as input: one of a professional dancer and one of a student. | |
2. Aligns the movements of both dancers, even if they perform at different rhythms. | |
3. Generates a single concatenated video showing the aligned movements of both dancers side-by-side. | |
4. Highlights the student's errors for easy identification. | |
5. Produces a text log of errors with corresponding timestamps. | |
This tool offering a detailed analysis of technique and areas for improvement. | |
""") | |
with gr.Accordion("Video formats:", open=False): | |
gr.Markdown(""" | |
For the input video to be playable in the browser, it must have a compatible container and codec combination. | |
Allowed combinations are: | |
- **.mp4** with **H.264** codec | |
- **.ogg** with **Theora** codec | |
- **.webm** with **VP9** codec | |
If the component detects that the output video would not be playable in the browser, it will attempt to convert it to a playable **.mp4** video. | |
The output video format is always **.mp4**, which is playable in the browser. The resolution of the output concatenated video is **2560x720**. | |
""") | |
with gr.Accordion("Settings clarifications:", open=False): | |
with gr.Accordion("Dynamic Time Warping:", open=False): | |
gr.Markdown(""" | |
Dynamic Time Warping is an algorithm that performs frame-by-frame alignment for videos with different speeds. | |
- **Winsorized mean**: Determines the portion of DTW paths, sorted from best to worst, to use for generating the mean DTW alignment. Reasonable values range from 0.25 to 0.6. | |
- **Savitzky-Golay Filter**: Enhances the capabilities of the Winsorized mean, making DTW alignment more similar to a strict line. Reasonable values range from 2 to 10. | |
""") | |
with gr.Accordion("Thresholds:", open=False): | |
gr.Markdown(""" | |
Thresholds are used to identify student errors in dance. If the difference in angle between the teacher's and student's videos exceeds this threshold, it is counted as an error. | |
- **Sensitive**: A threshold that is currently not used. | |
- **Standard**: A threshold for most angles. Reasonable values range from 20 to 40. | |
- **Insensitive**: A threshold for difficult areas, such as hands and toes. Reasonable values range from 35 to 55. | |
""") | |
with gr.Accordion("Patience:", open=False): | |
gr.Markdown(""" | |
Patience settings help prevent model errors by highlighting only those errors detected in consecutive frames. | |
Options: | |
- **One**: Utilizes 1 consecutive frame for error detection. | |
- **Two**: Utilizes 2 consecutive frames for error detection. | |
- **Three**: Utilizes 3 consecutive frames for error detection. | |
Guidelines: | |
- Option **One** is better for fast dances and videos with low frame rates. | |
- Option **Three** is better for slow dances and videos with high frame rates. | |
- Option **Two** provides intermediate performance and can be used for experimentation. | |
The patience setting allows you to balance between sensitivity and accuracy in error detection, depending on the dance style and video quality. | |
""") | |
with gr.Row(): | |
gr_button = gr.Button("Run Pose Comparison") | |
with gr.Row(): | |
gr.HTML("<div style='height: 100px;'></div>") | |
with gr.Row(): | |
output_merged = gr.Video(show_download_button=True) | |
with gr.Row(): | |
general_log = gr.TextArea(lines=10, label="Error log", scale=3) | |
text_log=gr.File(label="Download logs and settings", scale=1) | |
gr_button.click( | |
fn=video_identity, | |
inputs=[dtw_mean, dtw_filter, angles_sensitive, angles_common, angles_insensitive, trigger_state, show_arrows, input_teacher, input_student], | |
outputs=[output_merged, general_log, text_log] | |
) | |
if __name__ == "__main__": | |
demo.launch() |