reab5555 commited on
Commit
0228028
·
verified ·
1 Parent(s): 374d9c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -88
app.py CHANGED
@@ -4,9 +4,7 @@ from processing import process_input
4
  from transcription_diarization import diarize_audio
5
  from visualization import create_charts
6
  import time
7
- import re
8
  import cv2
9
- import os
10
  from config import openai_api_key
11
 
12
  # Load the model
@@ -34,63 +32,33 @@ def analyze_video(video_path, progress=gr.Progress()):
34
  end_time = time.time()
35
  execution_time = end_time - start_time
36
 
37
- output_components = [] # transcript
38
 
39
  output_components.append(f"Completed in {int(execution_time)} seconds.")
40
  output_components.append(gr.Textbox(value=transcription, label="Transcript", lines=10, visible=True))
41
 
42
- with gr.Tab(label=f'Description', visible=False):
43
- gr.Markdown(description_txt)
44
- gr.HTML("<div style='height: 20px;'></div>")
45
- gr.Image(value="appendix/AI Personality Detection flow - 1.png", label='Flowchart 1', width=1000)
46
- gr.Image(value="appendix/AI Personality Detection flow - 2.png", label='Flowchart 2', width=1000)
47
-
48
  for i, (speaker_id, speaker_charts) in enumerate(charts.items(), start=1):
49
- print(speaker_id)
50
  speaker_explanations = explanations[speaker_id]
51
  speaker_general_impression = general_impressions[speaker_id]
52
 
53
- with gr.Tab():
54
- with gr.TabItem(label=f'General Impression'):
55
- speaker_section1 = [
56
- gr.Markdown(f"### {speaker_id}", visible=True),
57
- gr.Textbox(value=speaker_general_impression, label="General Impression", visible=True, lines=10)
58
- ]
59
-
60
- with gr.TabItem(label=f'Attachment Styles'):
61
- speaker_section2 = [
62
- gr.Plot(value=speaker_charts.get("attachment", None), visible=True),
63
- gr.Plot(value=speaker_charts.get("dimensions", None), visible=True),
64
- gr.Textbox(value=speaker_explanations.get("attachment", ""), label="Attachment Styles Explanation",
65
- visible=True, lines=2)
66
- ]
67
-
68
- with gr.TabItem(label=f'Big Five Traits'):
69
- speaker_section3 = [
70
- gr.Plot(value=speaker_charts.get("bigfive", None), visible=True),
71
- gr.Textbox(value=speaker_explanations.get("bigfive", ""), label="Big Five Traits Explanation",
72
- visible=True, lines=2)
73
- ]
74
-
75
- with gr.TabItem(label=f'Personalities'):
76
- speaker_section4 = [
77
- gr.Plot(value=speaker_charts.get("personality", None), visible=True),
78
- gr.Textbox(value=speaker_explanations.get("personality", ""),
79
- label="Personality Disorders Explanation", visible=True, lines=2)
80
- ]
81
-
82
- output_components.extend(speaker_section1)
83
- output_components.extend(speaker_section2)
84
- output_components.extend(speaker_section3)
85
- output_components.extend(speaker_section4)
86
 
87
  # Pad with None for any missing speakers
88
- while len(output_components) < 28:
89
- output_components.extend([gr.update(visible=False)] * 9)
90
 
91
  return output_components
92
 
93
-
94
  def use_example_1():
95
  return "examples/Scenes.From.A.Marriage.US.mp4"
96
  def use_example_2():
@@ -111,6 +79,9 @@ def get_middle_frame(video_path):
111
  return preview_path
112
  return None
113
 
 
 
 
114
  with gr.Blocks() as iface:
115
  gr.Markdown("# Multiple-Speakers-Personality-Analyzer")
116
  gr.Markdown("This project provides an advanced AI system designed for diagnosing and profiling personality attributes from video content based on a single speaker or multiple speakers in a conversation.")
@@ -130,32 +101,17 @@ with gr.Blocks() as iface:
130
  output_components.append(transcript)
131
 
132
  for n in range(3): # Assuming maximum of 3 speakers
133
- with gr.Tab(label=f'Speaker {n + 1}', visible=True):
134
- with gr.TabItem(label=f'General Impression'):
135
- column_components1 = [
136
- gr.Markdown(visible=False),
137
- gr.Textbox(label="General Impression", visible=False)]
138
-
139
- with gr.TabItem(label=f'Attachment Styles'):
140
- column_components2 = [
141
- gr.Plot(visible=False),
142
- gr.Plot(visible=False),
143
- gr.Textbox(label="Attachment Styles Explanation", visible=False)]
144
-
145
- with gr.TabItem(label=f'Big Five Traits'):
146
- column_components3 = [
147
- gr.Plot(visible=False),
148
- gr.Textbox(label="Big Five Traits Explanation", visible=False)]
149
-
150
- with gr.TabItem(label=f'Personalities'):
151
- column_components4 = [
152
- gr.Plot(visible=False),
153
- gr.Textbox(label="Personality Disorders Explanation", visible=False)]
154
-
155
- output_components.extend(column_components1)
156
- output_components.extend(column_components2)
157
- output_components.extend(column_components3)
158
- output_components.extend(column_components4)
159
 
160
  with open('description.txt', 'r') as file:
161
  description_txt = file.read()
@@ -165,7 +121,6 @@ with gr.Blocks() as iface:
165
  gr.Image(value="appendix/AI Personality Detection flow - 1.png", label='Flowchart 1', width=1000)
166
  gr.Image(value="appendix/AI Personality Detection flow - 2.png", label='Flowchart 2', width=1000)
167
 
168
-
169
  gr.Markdown("### Example Videos")
170
  with gr.Row():
171
  with gr.Column(scale=1):
@@ -190,6 +145,10 @@ with gr.Blocks() as iface:
190
  use_example_button_3 = gr.Button("Load Example 3")
191
 
192
  analyze_button.click(
 
 
 
 
193
  fn=analyze_video,
194
  inputs=[video_input],
195
  outputs=output_components,
@@ -200,29 +159,46 @@ with gr.Blocks() as iface:
200
  fn=use_example_1,
201
  inputs=[],
202
  outputs=[video_input],
203
- ).then(fn=analyze_video,
204
- inputs=[video_input],
205
- outputs=output_components,
206
- show_progress=True
207
- )
 
 
 
 
 
 
208
  use_example_button_2.click(
209
  fn=use_example_2,
210
  inputs=[],
211
  outputs=[video_input],
212
- ).then(fn=analyze_video,
213
- inputs=[video_input],
214
- outputs=output_components,
215
- show_progress=True
216
- )
 
 
 
 
 
 
217
  use_example_button_3.click(
218
  fn=use_example_3,
219
  inputs=[],
220
  outputs=[video_input],
221
- ).then(fn=analyze_video,
222
- inputs=[video_input],
223
- outputs=output_components,
224
- show_progress=True
225
- )
 
 
 
 
 
226
 
227
  if __name__ == "__main__":
228
  iface.launch()
 
4
  from transcription_diarization import diarize_audio
5
  from visualization import create_charts
6
  import time
 
7
  import cv2
 
8
  from config import openai_api_key
9
 
10
  # Load the model
 
32
  end_time = time.time()
33
  execution_time = end_time - start_time
34
 
35
+ output_components = []
36
 
37
  output_components.append(f"Completed in {int(execution_time)} seconds.")
38
  output_components.append(gr.Textbox(value=transcription, label="Transcript", lines=10, visible=True))
39
 
 
 
 
 
 
 
40
  for i, (speaker_id, speaker_charts) in enumerate(charts.items(), start=1):
 
41
  speaker_explanations = explanations[speaker_id]
42
  speaker_general_impression = general_impressions[speaker_id]
43
 
44
+ output_components.extend([
45
+ gr.Markdown(f"### {speaker_id}", visible=True),
46
+ gr.Textbox(value=speaker_general_impression, label="General Impression", visible=True, lines=10),
47
+ gr.Plot(value=speaker_charts.get("attachment", None), visible=True),
48
+ gr.Plot(value=speaker_charts.get("dimensions", None), visible=True),
49
+ gr.Textbox(value=speaker_explanations.get("attachment", ""), label="Attachment Styles Explanation", visible=True, lines=2),
50
+ gr.Plot(value=speaker_charts.get("bigfive", None), visible=True),
51
+ gr.Textbox(value=speaker_explanations.get("bigfive", ""), label="Big Five Traits Explanation", visible=True, lines=2),
52
+ gr.Plot(value=speaker_charts.get("personality", None), visible=True),
53
+ gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation", visible=True, lines=2)
54
+ ])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  # Pad with None for any missing speakers
57
+ while len(output_components) < 29:
58
+ output_components.append(None)
59
 
60
  return output_components
61
 
 
62
  def use_example_1():
63
  return "examples/Scenes.From.A.Marriage.US.mp4"
64
  def use_example_2():
 
79
  return preview_path
80
  return None
81
 
82
+ def clear_outputs():
83
+ return [None] * 29
84
+
85
  with gr.Blocks() as iface:
86
  gr.Markdown("# Multiple-Speakers-Personality-Analyzer")
87
  gr.Markdown("This project provides an advanced AI system designed for diagnosing and profiling personality attributes from video content based on a single speaker or multiple speakers in a conversation.")
 
101
  output_components.append(transcript)
102
 
103
  for n in range(3): # Assuming maximum of 3 speakers
104
+ with gr.Tab(label=f'Speaker {n + 1}', visible=False) as tab:
105
+ gr.Markdown(visible=False)
106
+ gr.Textbox(label="General Impression", visible=False)
107
+ gr.Plot(visible=False)
108
+ gr.Plot(visible=False)
109
+ gr.Textbox(label="Attachment Styles Explanation", visible=False)
110
+ gr.Plot(visible=False)
111
+ gr.Textbox(label="Big Five Traits Explanation", visible=False)
112
+ gr.Plot(visible=False)
113
+ gr.Textbox(label="Personality Disorders Explanation", visible=False)
114
+ output_components.extend([tab] + [component for component in tab.children])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  with open('description.txt', 'r') as file:
117
  description_txt = file.read()
 
121
  gr.Image(value="appendix/AI Personality Detection flow - 1.png", label='Flowchart 1', width=1000)
122
  gr.Image(value="appendix/AI Personality Detection flow - 2.png", label='Flowchart 2', width=1000)
123
 
 
124
  gr.Markdown("### Example Videos")
125
  with gr.Row():
126
  with gr.Column(scale=1):
 
145
  use_example_button_3 = gr.Button("Load Example 3")
146
 
147
  analyze_button.click(
148
+ fn=clear_outputs,
149
+ inputs=[],
150
+ outputs=output_components
151
+ ).then(
152
  fn=analyze_video,
153
  inputs=[video_input],
154
  outputs=output_components,
 
159
  fn=use_example_1,
160
  inputs=[],
161
  outputs=[video_input],
162
+ ).then(
163
+ fn=clear_outputs,
164
+ inputs=[],
165
+ outputs=output_components
166
+ ).then(
167
+ fn=analyze_video,
168
+ inputs=[video_input],
169
+ outputs=output_components,
170
+ show_progress=True
171
+ )
172
+
173
  use_example_button_2.click(
174
  fn=use_example_2,
175
  inputs=[],
176
  outputs=[video_input],
177
+ ).then(
178
+ fn=clear_outputs,
179
+ inputs=[],
180
+ outputs=output_components
181
+ ).then(
182
+ fn=analyze_video,
183
+ inputs=[video_input],
184
+ outputs=output_components,
185
+ show_progress=True
186
+ )
187
+
188
  use_example_button_3.click(
189
  fn=use_example_3,
190
  inputs=[],
191
  outputs=[video_input],
192
+ ).then(
193
+ fn=clear_outputs,
194
+ inputs=[],
195
+ outputs=output_components
196
+ ).then(
197
+ fn=analyze_video,
198
+ inputs=[video_input],
199
+ outputs=output_components,
200
+ show_progress=True
201
+ )
202
 
203
  if __name__ == "__main__":
204
  iface.launch()