Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import time
|
4 |
-
import os
|
5 |
-
from pydub import AudioSegment
|
6 |
-
from pydub.silence import split_on_silence
|
7 |
-
|
8 |
-
openai_client = openai.OpenAI()
|
9 |
-
OPENAI_TRANSCRIPTION_MODEL = 'whisper-1'
|
10 |
-
whisper = openai_client.audio.transcriptions.create
|
11 |
-
WHISPER_TEMPERATURE = 0.0
|
12 |
-
|
13 |
-
def transcribe_audio(audio_file):
|
14 |
-
audio = AudioSegment.from_file(audio_file)
|
15 |
-
chunks = split_on_silence(audio, min_silence_len=500, silence_thresh=-40)
|
16 |
-
|
17 |
-
transcription = ""
|
18 |
-
nChunks = len(chunks)
|
19 |
-
print(f'PROCESSING {nChunks} chunks')
|
20 |
-
|
21 |
-
for i, chunk in enumerate(chunks):
|
22 |
-
chunk_file = f"CHUNKS/chunk_{i}.mp3"
|
23 |
-
chunk.export(chunk_file, format="mp3")
|
24 |
-
response = whisper(model = OPENAI_TRANSCRIPTION_MODEL,
|
25 |
-
file = open(chunk_file, 'rb'),
|
26 |
-
language = 'es',
|
27 |
-
temperature = WHISPER_TEMPERATURE) # to do, explore temperature
|
28 |
-
#print(dir(response))
|
29 |
-
transcription += response.text + " "
|
30 |
-
# os.remove(chunk_file) # concatenate at the end
|
31 |
-
|
32 |
-
yield transcription
|
33 |
|
34 |
iface = gr.Interface(
|
35 |
fn=transcribe_audio,
|
|
|
1 |
import gradio as gr
|
2 |
+
from libs.audio import transcribe_audio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
iface = gr.Interface(
|
5 |
fn=transcribe_audio,
|