reab5555's picture
Update app.py
871e711 verified
raw
history blame
2.7 kB
import gradio as gr
from processing import process_input
from visualization import update_visibility_and_charts
import os
def create_interface():
example_video_path = "examples/Scenes.From.A.Marriage.US.mp4"
with gr.Blocks() as iface:
gr.Markdown("# Personality Analysis Classification")
gr.Markdown("Upload a Video, TXT, or PDF file or use the example video.")
with gr.Row():
with gr.Column(scale=3):
input_file = gr.File(label="Upload File (TXT, PDF, or Video)")
with gr.Column(scale=1):
# Load the video directly when creating the interface
example_video = gr.Video(value=example_video_path, label="Example Video Preview")
example_button = gr.Button("Use Example Video")
with gr.Column():
progress = gr.Progress()
status_text = gr.Textbox(label="Status")
execution_time = gr.Textbox(label="Execution Time", visible=False)
detected_language = gr.Textbox(label="Detected Language", visible=False)
# Create placeholders for charts and explanations
charts_and_explanations = []
for _ in range(6): # 3 analysis types * 2 speakers
with gr.Row():
charts_and_explanations.append(gr.Plot(visible=False))
charts_and_explanations.append(gr.Plot(visible=False))
charts_and_explanations.append(gr.Textbox(visible=False))
def process_and_update(input_file):
if input_file is None:
return [gr.update(value="No file selected")] + [gr.update(visible=False)] * (len(charts_and_explanations) + 2)
# Process the input
results = process_input(input_file, progress=gr.Progress())
# Create and update charts and explanations
return update_visibility_and_charts(*results)
def use_example_video():
return example_video_path
input_file.upload(
fn=process_and_update,
inputs=[input_file],
outputs=[status_text, execution_time, detected_language] + charts_and_explanations
)
example_button.click(
fn=use_example_video,
inputs=[],
outputs=input_file
).then(
fn=process_and_update,
inputs=[input_file],
outputs=[status_text, execution_time, detected_language] + charts_and_explanations
)
return iface
iface = create_interface()
# Launch the app
if __name__ == "__main__":
iface.launch(share=True)