Robooze commited on
Commit
0d5d8ce
1 Parent(s): 249fca4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -4,31 +4,24 @@ import shutil
4
  import tempfile
5
  import os
6
 
7
- # vocabolario_LOUD = os.environ.get("VOCABOLARIO_LOUD")
8
  open_ai_key = os.environ.get("OPEN_AI_KEY")
9
  openai.api_key = open_ai_key
10
 
11
- def transcribe(audio):
12
 
13
  # the audio file has no extension. We make a .wav copy:
14
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio_file:
15
 
16
- # extract the file descriptor from the tuple
17
- audio_fd = audio[0]
18
-
19
- # open the file with its descriptor
20
- audio_file = os.fdopen(audio_fd, "rb")
21
-
22
- # copy the file content without closing it
23
- shutil.copyfileobj(audio_file, temp_audio_file)
24
 
25
  audio_filepath = temp_audio_file.name
26
  audio_file= open(audio_filepath, "rb")
27
 
28
- transcript = openai.Audio.transcribe("whisper-1", audio_file, language="en")
29
 
30
  return transcript["text"]
31
 
32
- app = gr.Interface(fn=transcribe, inputs=gr.Audio(source="upload"), outputs="text", title="Demo di trascrizione con vocabolario LOUD",description="Demo implementante l'API di Whisper personalizzato con vocabolario LOUD", live=True)
33
 
34
  app.launch()
 
4
  import tempfile
5
  import os
6
 
7
+ vocabolario_LOUD = os.environ.get("VOCABOLARIO_LOUD")
8
  open_ai_key = os.environ.get("OPEN_AI_KEY")
9
  openai.api_key = open_ai_key
10
 
11
+ def transcribe(audio_file_path):
12
 
13
  # the audio file has no extension. We make a .wav copy:
14
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio_file:
15
 
16
+ shutil.copy(audio_file_path, temp_audio_file.name)
 
 
 
 
 
 
 
17
 
18
  audio_filepath = temp_audio_file.name
19
  audio_file= open(audio_filepath, "rb")
20
 
21
+ transcript = openai.Audio.transcribe("whisper-1", audio_file, prompt=vocabolario_LOUD, language="it")
22
 
23
  return transcript["text"]
24
 
25
+ app = gr.Interface(fn=transcribe, inputs=gr.inputs.File(type="file"), outputs="text", title="Demo di trascrizione con vocabolario LOUD",description="Demo implementante l'API di Whisper personalizzato con vocabolario LOUD", live=True)
26
 
27
  app.launch()