vsrinivas commited on
Commit
1589ebc
·
verified ·
1 Parent(s): 7053531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -27
app.py CHANGED
@@ -33,23 +33,21 @@ language_codes = {"English":"en", "Hindi":"hi", "Portuguese":"pt", "Chinese":"zh
33
  "Ukrainian":"uk", "Greek":"el", "Czech":"cs", "Danish":"da", "Finnish":"fi",
34
  "Bulgarian":"bg", "Croatian":"hr", "Slovak":"sk"}
35
 
36
- # meeting_texts = []
37
  n_participants = 4 # This can be adjusted based on the number of people in the call
38
  language_choices = ["English", "Polish", "Hindi", "Arabic"]
39
 
40
  def clear_all():
41
- # global meeting_texts
42
- # meeting_texts = [] # Reset meeting texts
43
- return [None] * (n_participants * 5 + 1) # Reset outputs of transcripts, translated texts, and dubbed videos
44
 
45
 
46
  def wait_for_dubbing_completion(dubbing_id: str) -> bool:
47
  """
48
  Waits for the dubbing process to complete by periodically checking the status.
49
-
50
  Args:
51
  dubbing_id (str): The dubbing project id.
52
-
53
  Returns:
54
  bool: True if the dubbing is successful, False otherwise.
55
  """
@@ -77,11 +75,9 @@ def wait_for_dubbing_completion(dubbing_id: str) -> bool:
77
  def download_dubbed_file(dubbing_id: str, language_code: str) -> str:
78
  """
79
  Downloads the dubbed file for a given dubbing ID and language code.
80
-
81
  Args:
82
  dubbing_id: The ID of the dubbing project.
83
  language_code: The language code for the dubbing.
84
-
85
  Returns:
86
  The file path to the downloaded dubbed file.
87
  """
@@ -104,13 +100,11 @@ def create_dub_from_file(
104
  # ) -> Optional[str]:
105
  """
106
  Dubs an audio or video file from one language to another and saves the output.
107
-
108
  Args:
109
  input_file_path (str): The file path of the audio or video to dub.
110
  file_format (str): The file format of the input file.
111
  source_language (str): The language of the input file.
112
  target_language (str): The target language to dub into.
113
-
114
  Returns:
115
  Optional[str]: The file path of the dubbed file or None if operation failed.
116
  """
@@ -136,17 +130,20 @@ def create_dub_from_file(
136
  return None
137
 
138
 
139
- def summarize(meeting_texts):
140
  mt = ', '.join([f"{k}: {v}" for i in meeting_texts for k, v in i.items()])
141
  meeting_date_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
142
  meeting_texts = meeting_date_time + '\n' + mt
143
 
 
 
 
144
  minutes_of_meeting = ""
145
  for chunk in AI71(AI71_API_KEY.strip()).chat.completions.create(
146
  model="tiiuae/falcon-180b-chat",
147
  messages=[
148
  {"role": "system", "content": f"""You are an expereiced Secretary who can summarize meeting discussions into minutes of meeting.
149
- Summarize the meetings discussions provided as Speakerwise conversation.
150
  Strictly consider only the context given in user content {meeting_texts} for summarization.
151
  Ensure to mention the title as 'Minutes of Meeting held on {meeting_date_time} and present the summary with better viewing format and title in bold letters"""},
152
  {"role": "user", "content": meeting_texts},
@@ -195,12 +192,12 @@ def synthesize_speech(video, source_language,target_language):
195
  return dub_video
196
 
197
  # This function handles the processing when any participant speaks
198
- def process_speaker(video, speaker_idx, n_participants, meeting_texts, *language_list):
199
  transcript = speech_to_text(video)
200
 
201
  # Create outputs for each participant
202
  outputs = []
203
- # global meeting_texts
204
  def process_translation_dubbing(i):
205
  if i != speaker_idx:
206
  participant_language = language_codes[language_list[i]]
@@ -220,7 +217,6 @@ def process_speaker(video, speaker_idx, n_participants, meeting_texts, *language
220
  else:
221
  outputs.append(translated_text)
222
  outputs.append(dubbed_video)
223
-
224
  if speaker_idx == 0:
225
  meeting_texts.append({f"Speaker_{speaker_idx+1}":outputs[0]})
226
  else:
@@ -228,11 +224,9 @@ def process_speaker(video, speaker_idx, n_participants, meeting_texts, *language
228
 
229
  print(len(outputs))
230
  print(outputs)
231
- outputs.extend(meeting_texts)
232
  print('meeting_texts: ',meeting_texts)
233
  return outputs
234
 
235
-
236
  def create_participant_row(i, language_choices):
237
  """Creates the UI for a single participant."""
238
  with gr.Row():
@@ -243,15 +237,12 @@ def create_participant_row(i, language_choices):
243
  dubbed_video = gr.Video(label="Speaker's Dubbed Video")
244
  return video_input, language_dropdown, transcript_output, translated_text, dubbed_video
245
 
246
-
247
  # Main dynamic Gradio interface
248
  def create_gradio_interface(n_participants, language_choices):
249
  with gr.Blocks() as demo:
250
  gr.Markdown("""# LinguaPolis: Bridging Languages, Uniting Teams Globally - Multilingual Conference Call Simulation
251
  ## Record your video or upload your video and press the corresponding Submit button at the bottom""")
252
 
253
- # meeting_texts = []
254
-
255
  video_inputs = []
256
  language_dropdowns = []
257
  transcript_outputs = []
@@ -259,7 +250,7 @@ def create_gradio_interface(n_participants, language_choices):
259
  dubbed_videos = []
260
 
261
  clear_button = gr.Button("Clear All")
262
-
263
  # Create a row for each participant
264
  for i in range(n_participants):
265
  video_input, language_dropdown, transcript_output, translated_text, dubbed_video = create_participant_row(i, language_choices)
@@ -273,13 +264,12 @@ def create_gradio_interface(n_participants, language_choices):
273
  for i in range(n_participants):
274
  gr.Button(f"Submit Speaker {i+1}'s Speech").click(
275
  process_speaker,
276
- # [video_inputs[i], gr.State(i), gr.State(n_participants)] + [language_dropdowns[j] for j in range(n_participants)],
277
- [video_inputs[i], gr.State(i), gr.State(n_participants)] + [gr.State(value=[])] + [language_dropdowns[j] for j in range(n_participants)],
278
- [transcript_outputs[i]] + [k for j in zip(translated_texts[:i]+translated_texts[i+1:], dubbed_videos[:i]+dubbed_videos[i+1:]) for k in j] + [gr.State()]
279
  )
280
  minutes = gr.Textbox(label="Minutes of Meeting")
281
- gr.Button(f"Generate Minutes of meeting").click(summarize, meeting_texts, minutes)
282
-
283
  # Clear button to reset inputs and outputs
284
  clear_button.click(clear_all, None, [*video_inputs, *transcript_outputs, *translated_texts, *dubbed_videos, minutes])
285
 
@@ -287,4 +277,4 @@ def create_gradio_interface(n_participants, language_choices):
287
  demo.queue().launch(debug=True, share=True)
288
 
289
 
290
- create_gradio_interface(n_participants, language_choices)
 
33
  "Ukrainian":"uk", "Greek":"el", "Czech":"cs", "Danish":"da", "Finnish":"fi",
34
  "Bulgarian":"bg", "Croatian":"hr", "Slovak":"sk"}
35
 
36
+ meeting_texts = []
37
  n_participants = 4 # This can be adjusted based on the number of people in the call
38
  language_choices = ["English", "Polish", "Hindi", "Arabic"]
39
 
40
  def clear_all():
41
+ global meeting_texts
42
+ meeting_texts = [] # Reset meeting texts
43
+ return [None] * (n_participants * 4 + 1) # Reset outputs of transcripts, translated texts, and dubbed videos
44
 
45
 
46
  def wait_for_dubbing_completion(dubbing_id: str) -> bool:
47
  """
48
  Waits for the dubbing process to complete by periodically checking the status.
 
49
  Args:
50
  dubbing_id (str): The dubbing project id.
 
51
  Returns:
52
  bool: True if the dubbing is successful, False otherwise.
53
  """
 
75
  def download_dubbed_file(dubbing_id: str, language_code: str) -> str:
76
  """
77
  Downloads the dubbed file for a given dubbing ID and language code.
 
78
  Args:
79
  dubbing_id: The ID of the dubbing project.
80
  language_code: The language code for the dubbing.
 
81
  Returns:
82
  The file path to the downloaded dubbed file.
83
  """
 
100
  # ) -> Optional[str]:
101
  """
102
  Dubs an audio or video file from one language to another and saves the output.
 
103
  Args:
104
  input_file_path (str): The file path of the audio or video to dub.
105
  file_format (str): The file format of the input file.
106
  source_language (str): The language of the input file.
107
  target_language (str): The target language to dub into.
 
108
  Returns:
109
  Optional[str]: The file path of the dubbed file or None if operation failed.
110
  """
 
130
  return None
131
 
132
 
133
+ def summarize(meeting_texts=meeting_texts):
134
  mt = ', '.join([f"{k}: {v}" for i in meeting_texts for k, v in i.items()])
135
  meeting_date_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
136
  meeting_texts = meeting_date_time + '\n' + mt
137
 
138
+ # meeting_conversation_processed ='\n'.join(mt)
139
+ # print("M:", session_conversation_processed)
140
+
141
  minutes_of_meeting = ""
142
  for chunk in AI71(AI71_API_KEY.strip()).chat.completions.create(
143
  model="tiiuae/falcon-180b-chat",
144
  messages=[
145
  {"role": "system", "content": f"""You are an expereiced Secretary who can summarize meeting discussions into minutes of meeting.
146
+ Summarize the meetings discussions provided as Speakerwise conversation.
147
  Strictly consider only the context given in user content {meeting_texts} for summarization.
148
  Ensure to mention the title as 'Minutes of Meeting held on {meeting_date_time} and present the summary with better viewing format and title in bold letters"""},
149
  {"role": "user", "content": meeting_texts},
 
192
  return dub_video
193
 
194
  # This function handles the processing when any participant speaks
195
+ def process_speaker(video, speaker_idx, n_participants, *language_list):
196
  transcript = speech_to_text(video)
197
 
198
  # Create outputs for each participant
199
  outputs = []
200
+ global meeting_texts
201
  def process_translation_dubbing(i):
202
  if i != speaker_idx:
203
  participant_language = language_codes[language_list[i]]
 
217
  else:
218
  outputs.append(translated_text)
219
  outputs.append(dubbed_video)
 
220
  if speaker_idx == 0:
221
  meeting_texts.append({f"Speaker_{speaker_idx+1}":outputs[0]})
222
  else:
 
224
 
225
  print(len(outputs))
226
  print(outputs)
 
227
  print('meeting_texts: ',meeting_texts)
228
  return outputs
229
 
 
230
  def create_participant_row(i, language_choices):
231
  """Creates the UI for a single participant."""
232
  with gr.Row():
 
237
  dubbed_video = gr.Video(label="Speaker's Dubbed Video")
238
  return video_input, language_dropdown, transcript_output, translated_text, dubbed_video
239
 
 
240
  # Main dynamic Gradio interface
241
  def create_gradio_interface(n_participants, language_choices):
242
  with gr.Blocks() as demo:
243
  gr.Markdown("""# LinguaPolis: Bridging Languages, Uniting Teams Globally - Multilingual Conference Call Simulation
244
  ## Record your video or upload your video and press the corresponding Submit button at the bottom""")
245
 
 
 
246
  video_inputs = []
247
  language_dropdowns = []
248
  transcript_outputs = []
 
250
  dubbed_videos = []
251
 
252
  clear_button = gr.Button("Clear All")
253
+
254
  # Create a row for each participant
255
  for i in range(n_participants):
256
  video_input, language_dropdown, transcript_output, translated_text, dubbed_video = create_participant_row(i, language_choices)
 
264
  for i in range(n_participants):
265
  gr.Button(f"Submit Speaker {i+1}'s Speech").click(
266
  process_speaker,
267
+ [video_inputs[i], gr.State(i), gr.State(n_participants)] + [language_dropdowns[j] for j in range(n_participants)],
268
+ [transcript_outputs[i]] + [k for j in zip(translated_texts[:i]+translated_texts[i+1:], dubbed_videos[:i]+dubbed_videos[i+1:]) for k in j]
 
269
  )
270
  minutes = gr.Textbox(label="Minutes of Meeting")
271
+ gr.Button(f"Generate Minutes of meeting").click(summarize, None, minutes)
272
+
273
  # Clear button to reset inputs and outputs
274
  clear_button.click(clear_all, None, [*video_inputs, *transcript_outputs, *translated_texts, *dubbed_videos, minutes])
275
 
 
277
  demo.queue().launch(debug=True, share=True)
278
 
279
 
280
+ create_gradio_interface(n_participants, language_choices)