Spaces:
Running
Running
File size: 926 Bytes
d8d71eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import gradio as gr
import openai
import shutil
import tempfile
import os
vocabolario_LOUD = os.environ.get("VOCABOLARIO_LOUD")
open_ai_key = os.environ.get("OPEN_AI_KEY")
openai.api_key = open_ai_key
def transcribe(audio):
# the audio file has no extension. We mae a .wav copy:
with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio_file:
shutil.copy(audio, temp_audio_file.name)
audio_filepath = temp_audio_file.name
audio_file= open(audio_filepath, "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file, prompt=vocabolario_LOUD, language="it")
return transcript["text"]
app = gr.Interface(fn=transcribe, inputs=gr.Microphone(type="filepath"), outputs="text", title="Demo di trascrizione con vocabolario LOUD",description="Demo implementante l'API di Whisper personalizzato con vocabolario LOUD", theme="dark-peach")
app.launch()
|