Spaces:
Runtime error
Runtime error
Commit ·
926bc70
1
Parent(s): 01bdfbb
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,39 @@
|
|
| 1 |
import time
|
| 2 |
import random
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def user(user_message, history):
|
| 9 |
return "", history + [[user_message, None]]
|
| 10 |
|
| 11 |
-
def transcribe(audio):
|
| 12 |
-
text = p(audio)["text"]
|
| 13 |
-
return text
|
| 14 |
-
|
| 15 |
def bot(history):
|
| 16 |
bot_message = random.choice(["How are you?", "I wanted to tell you that...", "hehehe", "huihuihuihui", "I'm very hungry"])
|
| 17 |
history[-1][1] = ""
|
|
|
|
| 1 |
import time
|
| 2 |
import random
|
| 3 |
+
import whisper
|
| 4 |
import gradio as gr
|
| 5 |
from transformers import pipeline
|
| 6 |
|
| 7 |
+
transcription_model = whisper.load_model("small")
|
| 8 |
+
|
| 9 |
+
def transcribe(audio):
|
| 10 |
+
|
| 11 |
+
# time.sleep(3)
|
| 12 |
+
# load audio and pad/trim it to fit 30 seconds
|
| 13 |
+
audio = whisper.load_audio(audio)
|
| 14 |
+
audio = whisper.pad_or_trim(audio)
|
| 15 |
+
|
| 16 |
+
# make log-Mel spectrogram and move to the same device as the transcription_model
|
| 17 |
+
mel = whisper.log_mel_spectrogram(audio).to(transcription_model.device)
|
| 18 |
+
|
| 19 |
+
# detect the spoken language
|
| 20 |
+
_, probs = transcription_model.detect_language(mel)
|
| 21 |
+
# print(f"Detected language: {max(probs, key=probs.get)}")
|
| 22 |
+
|
| 23 |
+
# decode the audio
|
| 24 |
+
options = whisper.DecodingOptions(fp16 = False)
|
| 25 |
+
result = whisper.decode(transcription_model, mel, options)
|
| 26 |
+
return result.text
|
| 27 |
+
|
| 28 |
+
# p = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
| 29 |
+
|
| 30 |
+
# def transcribe(audio):
|
| 31 |
+
# text = p(audio)["text"]
|
| 32 |
+
# return text
|
| 33 |
|
| 34 |
def user(user_message, history):
|
| 35 |
return "", history + [[user_message, None]]
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def bot(history):
|
| 38 |
bot_message = random.choice(["How are you?", "I wanted to tell you that...", "hehehe", "huihuihuihui", "I'm very hungry"])
|
| 39 |
history[-1][1] = ""
|