Spaces:
Sleeping
Sleeping
| import os | |
| #os.system("python -m pip install --upgrade pip") | |
| os.system("pip install git+https://github.com/openai/whisper.git") | |
| #os.system("pip install --upgrade gradio") | |
| import gradio as gr | |
| import torch | |
| import whisper | |
| import soundfile as sf | |
| #device = "cuda" if torch.cuda.is_available() else "cpu" | |
| #whisper_model = whisper.load_model("tiny.en", device=device) | |
| whisper_model = whisper.load_model("tiny.en") | |
| def audio2text(audio): | |
| f = sf.SoundFile(audio) | |
| seconds = int(len(f) / f.samplerate) | |
| seconds = seconds * 16000 | |
| audio = whisper.load_audio(audio) | |
| audio = whisper.pad_or_trim(audio, length=int(seconds)) | |
| result = whisper_model.transcribe(audio=audio, language="en") | |
| huh = result["text"] | |
| return huh | |
| input_audio = gr.Audio(source="upload", type="filepath") | |
| output_text = gr.Textbox() | |
| interface = gr.Interface( | |
| fn=audio2text, | |
| inputs=input_audio, | |
| outputs=output_text, | |
| ) | |
| interface.launch() |