Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,10 +12,7 @@ llm = load_model(openai_api_key)
|
|
12 |
def analyze_video(video_path, progress=gr.Progress()):
|
13 |
start_time = time.time()
|
14 |
if not video_path:
|
15 |
-
return
|
16 |
-
"transcript": gr.Textbox(value="Please upload a video file.", label="Error"),
|
17 |
-
"execution_info": gr.Textbox(value="Analysis not started.", label="Execution Information")
|
18 |
-
}
|
19 |
|
20 |
progress(0, desc="Starting analysis...")
|
21 |
progress(0.2, desc="Starting transcription and diarization")
|
@@ -35,53 +32,52 @@ def analyze_video(video_path, progress=gr.Progress()):
|
|
35 |
execution_time = end_time - start_time
|
36 |
|
37 |
output_components = {
|
38 |
-
"transcript":
|
|
|
39 |
}
|
40 |
|
41 |
for i, (speaker_id, speaker_charts) in enumerate(charts.items(), start=1):
|
42 |
speaker_explanations = explanations[speaker_id]
|
43 |
speaker_general_impression = general_impressions[speaker_id]
|
44 |
output_components.update({
|
45 |
-
f"speaker_{i}_header":
|
46 |
-
f"speaker_{i}_impression":
|
47 |
-
f"speaker_{i}_attachment":
|
48 |
-
f"speaker_{i}_attachment_exp":
|
49 |
-
f"speaker_{i}_dimensions":
|
50 |
-
f"speaker_{i}_bigfive":
|
51 |
-
f"speaker_{i}_bigfive_exp":
|
52 |
-
f"speaker_{i}_personality":
|
53 |
-
f"speaker_{i}_personality_exp":
|
54 |
})
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
updates = []
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
updates.append(gr.update(visible=True))
|
69 |
-
updates.extend([
|
70 |
-
gr.update(value=components[f"speaker_{i}_header"].value),
|
71 |
-
gr.update(value=components[f"speaker_{i}_impression"].value),
|
72 |
-
gr.update(value=components[f"speaker_{i}_attachment"].value),
|
73 |
-
gr.update(value=components[f"speaker_{i}_attachment_exp"].value),
|
74 |
-
gr.update(value=components[f"speaker_{i}_dimensions"].value),
|
75 |
-
gr.update(value=components[f"speaker_{i}_bigfive"].value),
|
76 |
-
gr.update(value=components[f"speaker_{i}_bigfive_exp"].value),
|
77 |
-
gr.update(value=components[f"speaker_{i}_personality"].value),
|
78 |
-
gr.update(value=components[f"speaker_{i}_personality_exp"].value),
|
79 |
-
])
|
80 |
else:
|
81 |
updates.append(gr.update(visible=False))
|
82 |
-
updates.append(gr.update(value=components["execution_info"].value, visible=True))
|
83 |
return updates
|
84 |
|
|
|
|
|
|
|
85 |
with gr.Blocks() as iface:
|
86 |
gr.Markdown("# AI Personality Detection")
|
87 |
|
@@ -101,28 +97,33 @@ with gr.Blocks() as iface:
|
|
101 |
speaker_outputs = []
|
102 |
for i in range(1, 4): # Assuming a maximum of 3 speakers
|
103 |
with gr.Column(visible=False) as speaker_column:
|
104 |
-
gr.Markdown(f"## Speaker {i}")
|
105 |
-
gr.Textbox(label="General Impression", lines=3)
|
106 |
-
gr.Plot(label="Attachment Styles")
|
107 |
-
gr.Textbox(label="Attachment Styles Explanation")
|
108 |
-
gr.Plot(label="Attachment Dimensions")
|
109 |
-
gr.Plot(label="Big Five Traits")
|
110 |
-
gr.Textbox(label="Big Five Traits Explanation")
|
111 |
-
gr.Plot(label="Personality Disorders")
|
112 |
-
gr.Textbox(label="Personality Disorders Explanation")
|
113 |
-
speaker_outputs.
|
|
|
|
|
|
|
|
|
114 |
execution_info = gr.Textbox(label="Execution Information", visible=False)
|
115 |
|
|
|
116 |
|
117 |
analyze_button.click(
|
118 |
fn=analyze_video,
|
119 |
inputs=[video_input],
|
120 |
-
outputs=
|
121 |
show_progress=True
|
122 |
).then(
|
123 |
fn=update_output,
|
124 |
-
inputs=
|
125 |
-
outputs=
|
126 |
)
|
127 |
|
128 |
use_example_button.click(
|
@@ -132,12 +133,12 @@ with gr.Blocks() as iface:
|
|
132 |
).then(
|
133 |
fn=analyze_video,
|
134 |
inputs=[video_input],
|
135 |
-
outputs=
|
136 |
show_progress=True
|
137 |
).then(
|
138 |
fn=update_output,
|
139 |
-
inputs=
|
140 |
-
outputs=
|
141 |
)
|
142 |
|
143 |
if __name__ == "__main__":
|
|
|
12 |
def analyze_video(video_path, progress=gr.Progress()):
|
13 |
start_time = time.time()
|
14 |
if not video_path:
|
15 |
+
return [None] * 29 # Return None for all outputs
|
|
|
|
|
|
|
16 |
|
17 |
progress(0, desc="Starting analysis...")
|
18 |
progress(0.2, desc="Starting transcription and diarization")
|
|
|
32 |
execution_time = end_time - start_time
|
33 |
|
34 |
output_components = {
|
35 |
+
"transcript": transcription,
|
36 |
+
"execution_info": f"Completed in {int(execution_time)} seconds."
|
37 |
}
|
38 |
|
39 |
for i, (speaker_id, speaker_charts) in enumerate(charts.items(), start=1):
|
40 |
speaker_explanations = explanations[speaker_id]
|
41 |
speaker_general_impression = general_impressions[speaker_id]
|
42 |
output_components.update({
|
43 |
+
f"speaker_{i}_header": f"## {speaker_id}",
|
44 |
+
f"speaker_{i}_impression": speaker_general_impression,
|
45 |
+
f"speaker_{i}_attachment": speaker_charts["attachment"],
|
46 |
+
f"speaker_{i}_attachment_exp": speaker_explanations["attachment"],
|
47 |
+
f"speaker_{i}_dimensions": speaker_charts["dimensions"],
|
48 |
+
f"speaker_{i}_bigfive": speaker_charts["bigfive"],
|
49 |
+
f"speaker_{i}_bigfive_exp": speaker_explanations["bigfive"],
|
50 |
+
f"speaker_{i}_personality": speaker_charts["personality"],
|
51 |
+
f"speaker_{i}_personality_exp": speaker_explanations["personality"],
|
52 |
})
|
53 |
|
54 |
+
# Convert the dictionary to a list of outputs
|
55 |
+
return [output_components.get(key, None) for key in [
|
56 |
+
"transcript",
|
57 |
+
"speaker_1_header", "speaker_1_impression", "speaker_1_attachment", "speaker_1_attachment_exp",
|
58 |
+
"speaker_1_dimensions", "speaker_1_bigfive", "speaker_1_bigfive_exp", "speaker_1_personality",
|
59 |
+
"speaker_1_personality_exp",
|
60 |
+
"speaker_2_header", "speaker_2_impression", "speaker_2_attachment", "speaker_2_attachment_exp",
|
61 |
+
"speaker_2_dimensions", "speaker_2_bigfive", "speaker_2_bigfive_exp", "speaker_2_personality",
|
62 |
+
"speaker_2_personality_exp",
|
63 |
+
"speaker_3_header", "speaker_3_impression", "speaker_3_attachment", "speaker_3_attachment_exp",
|
64 |
+
"speaker_3_dimensions", "speaker_3_bigfive", "speaker_3_bigfive_exp", "speaker_3_personality",
|
65 |
+
"speaker_3_personality_exp",
|
66 |
+
"execution_info"
|
67 |
+
]]
|
68 |
+
|
69 |
+
def update_output(*args):
|
70 |
updates = []
|
71 |
+
for arg in args:
|
72 |
+
if arg is not None:
|
73 |
+
updates.append(gr.update(value=arg, visible=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
else:
|
75 |
updates.append(gr.update(visible=False))
|
|
|
76 |
return updates
|
77 |
|
78 |
+
def use_example():
|
79 |
+
return "examples/Scenes.From.A.Marriage.US.mp4"
|
80 |
+
|
81 |
with gr.Blocks() as iface:
|
82 |
gr.Markdown("# AI Personality Detection")
|
83 |
|
|
|
97 |
speaker_outputs = []
|
98 |
for i in range(1, 4): # Assuming a maximum of 3 speakers
|
99 |
with gr.Column(visible=False) as speaker_column:
|
100 |
+
speaker_header = gr.Markdown(f"## Speaker {i}")
|
101 |
+
speaker_impression = gr.Textbox(label="General Impression", lines=3)
|
102 |
+
speaker_attachment = gr.Plot(label="Attachment Styles")
|
103 |
+
speaker_attachment_exp = gr.Textbox(label="Attachment Styles Explanation")
|
104 |
+
speaker_dimensions = gr.Plot(label="Attachment Dimensions")
|
105 |
+
speaker_bigfive = gr.Plot(label="Big Five Traits")
|
106 |
+
speaker_bigfive_exp = gr.Textbox(label="Big Five Traits Explanation")
|
107 |
+
speaker_personality = gr.Plot(label="Personality Disorders")
|
108 |
+
speaker_personality_exp = gr.Textbox(label="Personality Disorders Explanation")
|
109 |
+
speaker_outputs.extend([
|
110 |
+
speaker_header, speaker_impression, speaker_attachment, speaker_attachment_exp,
|
111 |
+
speaker_dimensions, speaker_bigfive, speaker_bigfive_exp, speaker_personality,
|
112 |
+
speaker_personality_exp
|
113 |
+
])
|
114 |
execution_info = gr.Textbox(label="Execution Information", visible=False)
|
115 |
|
116 |
+
all_outputs = [transcript_output] + speaker_outputs + [execution_info]
|
117 |
|
118 |
analyze_button.click(
|
119 |
fn=analyze_video,
|
120 |
inputs=[video_input],
|
121 |
+
outputs=all_outputs,
|
122 |
show_progress=True
|
123 |
).then(
|
124 |
fn=update_output,
|
125 |
+
inputs=all_outputs,
|
126 |
+
outputs=all_outputs,
|
127 |
)
|
128 |
|
129 |
use_example_button.click(
|
|
|
133 |
).then(
|
134 |
fn=analyze_video,
|
135 |
inputs=[video_input],
|
136 |
+
outputs=all_outputs,
|
137 |
show_progress=True
|
138 |
).then(
|
139 |
fn=update_output,
|
140 |
+
inputs=all_outputs,
|
141 |
+
outputs=all_outputs,
|
142 |
)
|
143 |
|
144 |
if __name__ == "__main__":
|