File size: 5,507 Bytes
b8a7acb
 
 
 
a26ac7e
8505717
b8a7acb
 
 
 
 
3670697
c114fac
 
119b8cd
c114fac
 
 
3670697
c114fac
 
 
 
4855721
c114fac
 
75ea1cc
c114fac
 
 
 
 
26a111a
c114fac
e77657a
c114fac
f9f3cf4
26a111a
fd65dfa
 
119b8cd
fd65dfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
875db1b
 
fd65dfa
875db1b
119b8cd
875db1b
 
e77657a
119b8cd
 
4c637de
1e7c569
 
 
2078afe
336fe2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd65dfa
336fe2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1641d0b
466cd11
9ba8687
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import gradio as gr
from llm_loader import load_model
from processing import process_input
from transcription_diarization import diarize_audio
from visualization import create_charts
import time
from config import openai_api_key

# Load the model
llm = load_model(openai_api_key)

def analyze_video(video_path, progress=gr.Progress()):
    start_time = time.time()
    if not video_path:
        return [None] * 29  # Return None for all outputs

    progress(0, desc="Starting analysis...")
    progress(0.2, desc="Starting transcription and diarization")
    transcription = diarize_audio(video_path)
    progress(0.5, desc="Transcription and diarization complete.")

    progress(0.6, desc="Processing transcription")
    results = process_input(transcription, llm)
    progress(0.7, desc="Transcription processing complete.")

    progress(0.9, desc="Generating charts")
    charts, explanations, general_impressions = create_charts(results)
    progress(1.0, desc="Charts generation complete.")

    end_time = time.time()
    execution_time = end_time - start_time

    output_components = [transcription]  # transcript

    for i, (speaker_id, speaker_charts) in enumerate(charts.items(), start=1):
        speaker_explanations = explanations[speaker_id]
        speaker_general_impression = general_impressions[speaker_id]

        speaker_section = [
            gr.Markdown(f"## {speaker_id}", visible=True),
            speaker_general_impression,  # speaker impression
            gr.Textbox(value=speaker_general_impression.get("general_impression", ""), label="General Impression",
                       visible=True),
            gr.Plot(value=speaker_charts.get("attachment", None), visible=True),
            gr.Plot(value=speaker_charts.get("dimensions", None), visible=True),

            gr.Textbox(value=speaker_explanations.get("attachment", ""), label="Attachment Styles Explanation",
                       visible=True),
            gr.Plot(value=speaker_charts.get("bigfive", None), visible=True),
            gr.Textbox(value=speaker_explanations.get("bigfive", ""), label="Big Five Traits Explanation",
                       visible=True),
            gr.Plot(value=speaker_charts.get("personality", None), visible=True),
            gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation",
                       visible=True),
        ]
        output_components.extend(speaker_section)
        
    # Pad with None for any missing speakers
    while len(output_components) < 28:
        output_components.extend([gr.update(visible=False)] * 9)

    output_components.append(f"Completed in {int(execution_time)} seconds.")  # execution info

    return output_components

def update_output(*args):
    return [gr.update(value=arg, visible=arg is not None) for arg in args]

def use_example():
    return "examples/Scenes.From.A.Marriage.US.mp4"

with gr.Blocks() as iface:
    gr.Markdown("# AI Personality Detection")
    
    with gr.Row():
        with gr.Column(scale=3):
            gr.Markdown("Upload a video")
            video_input = gr.Video(label="Upload Video")
            analyze_button = gr.Button("Analyze")
        with gr.Column(scale=1):
            gr.Markdown("Example Video")
            example_video = gr.Video("examples/Scenes.From.A.Marriage.US.mp4", label="Example Video")
            use_example_button = gr.Button("Use Example Video")

    # Create placeholder components for output
    with gr.Column() as output_container:
        transcript_output = gr.Textbox(label="Transcript", lines=10, visible=False)
        speaker_outputs = []
        for i in range(1, 4):
            with gr.Column(visible=False) as speaker_column:
                speaker_header = gr.Markdown(f"## Speaker {i}")
                speaker_impression = gr.Textbox(label="General Impression", lines=3)
                speaker_attachment = gr.Plot(label="Attachment Styles")
                speaker_attachment_exp = gr.Textbox(label="Attachment Styles Explanation")
                speaker_dimensions = gr.Plot(label="Attachment Dimensions")
                speaker_bigfive = gr.Plot(label="Big Five Traits")
                speaker_bigfive_exp = gr.Textbox(label="Big Five Traits Explanation")
                speaker_personality = gr.Plot(label="Personality Disorders")
                speaker_personality_exp = gr.Textbox(label="Personality Disorders Explanation")
            speaker_outputs.extend([
                speaker_header, speaker_impression, speaker_attachment, speaker_attachment_exp,
                speaker_dimensions, speaker_bigfive, speaker_bigfive_exp, speaker_personality,
                speaker_personality_exp
            ])
        execution_info = gr.Textbox(label="Execution Information", visible=True)

    all_outputs = [transcript_output] + speaker_outputs + [execution_info]

    analyze_button.click(
        fn=analyze_video,
        inputs=[video_input],
        outputs=all_outputs,
        show_progress=True
    ).then(
        fn=update_output,
        inputs=all_outputs,
        outputs=all_outputs
    )

    use_example_button.click(
        fn=use_example,
        inputs=[],
        outputs=[video_input],
    ).then(
        fn=analyze_video,
        inputs=[video_input],
        outputs=all_outputs,
        show_progress=True
    ).then(
        fn=update_output,
        inputs=all_outputs,
        outputs=all_outputs
    )

if __name__ == "__main__":
    iface.launch()