Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,31 +4,24 @@ import shutil
|
|
4 |
import tempfile
|
5 |
import os
|
6 |
|
7 |
-
|
8 |
open_ai_key = os.environ.get("OPEN_AI_KEY")
|
9 |
openai.api_key = open_ai_key
|
10 |
|
11 |
-
def transcribe(
|
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 |
-
|
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="
|
29 |
|
30 |
return transcript["text"]
|
31 |
|
32 |
-
app = gr.Interface(fn=transcribe, inputs=gr.
|
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()
|