Depreesion / tabs /sleep_quality.py
vitorcalvi's picture
pre-launch
fc286f6
raw
history blame
1.33 kB
import gradio as gr
from app.app_utils import preprocess_video_and_predict_sleep_quality
def clear_sleep_quality_info():
return [gr.Video(value=None)] * 3 + [gr.Image(value=None), gr.Plot(value=None)]
def create_sleep_quality_tab():
with gr.Row():
with gr.Column(scale=1):
input_video = gr.Video(elem_classes="video1")
with gr.Row():
clear_btn = gr.Button("Clear")
submit_btn = gr.Button("Analyze", elem_classes="submit")
with gr.Column(scale=1, elem_classes="dl4"):
outputs = [
gr.Video(label=label, elem_classes=f"video{i+2}")
for i, label in enumerate(["Original video", "Pre-processed video", "Sleep quality analysis"])
]
outputs.extend([
gr.Image(label="Eye bags detection", elem_classes="eyebags"),
gr.Plot(label="Sleep quality indicators", elem_classes="stat")
])
submit_btn.click(
fn=preprocess_video_and_predict_sleep_quality,
inputs=input_video,
outputs=outputs,
queue=True,
)
clear_btn.click(
fn=clear_sleep_quality_info,
outputs=[input_video] + outputs,
queue=True,
)
gr.Examples(["./assets/videos/fitness.mp4"], inputs=[input_video])