Spaces:
Sleeping
Sleeping
Commit ·
46e047b
1
Parent(s): 3eeee8c
Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
#os.system("python -m pip install --upgrade pip")
|
| 3 |
+
os.system("pip install git+https://github.com/openai/whisper.git")
|
| 4 |
+
#os.system("pip install --upgrade gradio")
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import torch
|
| 7 |
+
import whisper
|
| 8 |
+
import soundfile as sf
|
| 9 |
+
|
| 10 |
+
#device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
#whisper_model = whisper.load_model("tiny.en", device=device)
|
| 12 |
+
whisper_model = whisper.load_model("tiny.en")
|
| 13 |
+
|
| 14 |
+
def audio2text(audio):
|
| 15 |
+
f = sf.SoundFile(audio)
|
| 16 |
+
seconds = int(len(f) / f.samplerate)
|
| 17 |
+
seconds = seconds * 16000
|
| 18 |
+
audio = whisper.load_audio(audio)
|
| 19 |
+
audio = whisper.pad_or_trim(audio, length=int(seconds))
|
| 20 |
+
result = whisper_model.transcribe(audio=audio, language="en")
|
| 21 |
+
huh = result["text"]
|
| 22 |
+
return huh
|
| 23 |
+
|
| 24 |
+
input_audio = gr.Audio(source="upload", type="filepath")
|
| 25 |
+
output_text = gr.Textbox()
|
| 26 |
+
|
| 27 |
+
interface = gr.Interface(
|
| 28 |
+
fn=audio2text,
|
| 29 |
+
inputs=input_audio,
|
| 30 |
+
outputs=output_text,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
soundfile
|