Letsch22 commited on
Commit
010c52a
1 Parent(s): 5e8b0f6

Simplify video transcription

Browse files
Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import urllib.request
3
- import subprocess
4
  from dataclasses import dataclass
5
  from time import sleep
6
  from typing import Dict, List, Generator
@@ -28,24 +27,6 @@ class MockInterviewer:
28
  self._assistant_id_cache: Dict[Config, str] = {}
29
  self.clear_thread()
30
 
31
- def convert_webm_to_mp3(input_webm, output_mp3):
32
- command = [
33
- 'ffmpeg',
34
- '-i', input_webm, # Input file
35
- '-vn', # No video (remove video stream)
36
- '-ab', '160k', # Audio bitrate
37
- '-ar', '44100', # Audio sample rate
38
- '-y', # Overwrite output file if it exists
39
- '-f', 'mp3', # Output format
40
- output_mp3 # Output file
41
- ]
42
- try:
43
- subprocess.run(command, check=True)
44
- print(f"File converted successfully and saved as {output_mp3}")
45
- except subprocess.CalledProcessError as e:
46
- print(f"An error occurred while converting the file: {e}")
47
-
48
-
49
  def chat_with_text(
50
  self,
51
  message: Dict,
@@ -61,7 +42,7 @@ class MockInterviewer:
61
  config = Config(job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count)
62
  yield self._chat(message, config)
63
 
64
- def chat_with_audio(
65
  self,
66
  video: str,
67
  job_role: str,
@@ -72,14 +53,12 @@ class MockInterviewer:
72
  situational_count: int,
73
  case_count: int
74
  ) -> str:
75
- audio = 'temp_audio.mp3'
76
- MockInterviewer.convert_webm_to_mp3(video,audio)
77
- with open(audio, 'rb') as audio_file:
78
  transcriptions = self._client.audio.transcriptions.create(
79
  model='whisper-1',
80
- file=audio_file,
81
  )
82
- os.remove(audio)
83
  config = Config(job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count)
84
  response = self._chat(transcriptions.text, config)
85
  return [(transcriptions.text, response)]
@@ -206,14 +185,12 @@ with gr.Blocks(theme=theme) as demo:
206
  additional_inputs=[job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count],
207
  retry_btn=None,
208
  undo_btn=None)
209
-
210
- chat_interface.chatbot.height= '45vh'
211
 
212
  chat_interface.load(mock_interviewer.clear_thread)
213
  chat_interface.clear_btn.click(mock_interviewer.clear_thread)
214
 
215
  video = gr.Video(sources='webcam', include_audio=True)
216
- video.stop_recording(fn=mock_interviewer.chat_with_audio,
217
  inputs=[video, job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count],
218
  outputs=[chat_interface.chatbot],
219
  api_name=False).then(lambda:None, None, video, queue=False)
 
1
  import os
2
  import urllib.request
 
3
  from dataclasses import dataclass
4
  from time import sleep
5
  from typing import Dict, List, Generator
 
27
  self._assistant_id_cache: Dict[Config, str] = {}
28
  self.clear_thread()
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def chat_with_text(
31
  self,
32
  message: Dict,
 
42
  config = Config(job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count)
43
  yield self._chat(message, config)
44
 
45
+ def chat_with_video(
46
  self,
47
  video: str,
48
  job_role: str,
 
53
  situational_count: int,
54
  case_count: int
55
  ) -> str:
56
+ with open(video, 'rb') as file:
 
 
57
  transcriptions = self._client.audio.transcriptions.create(
58
  model='whisper-1',
59
+ file=file,
60
  )
61
+ os.remove(video)
62
  config = Config(job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count)
63
  response = self._chat(transcriptions.text, config)
64
  return [(transcriptions.text, response)]
 
185
  additional_inputs=[job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count],
186
  retry_btn=None,
187
  undo_btn=None)
 
 
188
 
189
  chat_interface.load(mock_interviewer.clear_thread)
190
  chat_interface.clear_btn.click(mock_interviewer.clear_thread)
191
 
192
  video = gr.Video(sources='webcam', include_audio=True)
193
+ video.stop_recording(fn=mock_interviewer.chat_with_video,
194
  inputs=[video, job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count],
195
  outputs=[chat_interface.chatbot],
196
  api_name=False).then(lambda:None, None, video, queue=False)