acrep commited on
Commit
02a72ca
·
1 Parent(s): 823b5c6

Added video input capability

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -1,5 +1,6 @@
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,6 +28,24 @@ class MockInterviewer:
27
  self._assistant_id_cache: Dict[Config, str] = {}
28
  self.clear_thread()
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def chat_with_text(
31
  self,
32
  message: Dict,
@@ -44,7 +63,7 @@ class MockInterviewer:
44
 
45
  def chat_with_audio(
46
  self,
47
- audio: str,
48
  job_role: str,
49
  company: str,
50
  job_description: str,
@@ -53,6 +72,8 @@ class MockInterviewer:
53
  situational_count: int,
54
  case_count: int
55
  ) -> str:
 
 
56
  with open(audio, 'rb') as audio_file:
57
  transcriptions = self._client.audio.transcriptions.create(
58
  model='whisper-1',
@@ -62,7 +83,7 @@ class MockInterviewer:
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)]
65
-
66
  def clear_thread(self) -> None:
67
  print('Initializing new thread')
68
  self._thread = self._client.beta.threads.create()
@@ -191,9 +212,9 @@ with gr.Blocks(theme=theme) as demo:
191
  chat_interface.load(mock_interviewer.clear_thread)
192
  chat_interface.clear_btn.click(mock_interviewer.clear_thread)
193
 
194
- audio = gr.Audio(sources=['microphone'], type='filepath', editable=False)
195
- audio.stop_recording(fn=mock_interviewer.chat_with_audio,
196
- inputs=[audio, job_role, company, job_description, behavioral_count, technical_count, situational_count, case_count],
197
  outputs=[chat_interface.chatbot],
198
  api_name=False)
199
 
 
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
  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,
 
63
 
64
  def chat_with_audio(
65
  self,
66
+ video: str,
67
  job_role: str,
68
  company: str,
69
  job_description: str,
 
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',
 
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)]
86
+
87
  def clear_thread(self) -> None:
88
  print('Initializing new thread')
89
  self._thread = self._client.beta.threads.create()
 
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)
220