Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +41 -0
- gradio_app.py +13 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import modal
|
| 2 |
+
|
| 3 |
+
app = modal.App("whisper-app")
|
| 4 |
+
|
| 5 |
+
# Define container with required packages
|
| 6 |
+
image = (
|
| 7 |
+
modal.Image.debian_slim()
|
| 8 |
+
.pip_install("openai-whisper", "requests")
|
| 9 |
+
.apt_install("ffmpeg")
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
@app.cls(image=image)
|
| 13 |
+
class WhisperModel:
|
| 14 |
+
def __init__(self):
|
| 15 |
+
self.model = None
|
| 16 |
+
|
| 17 |
+
@modal.enter() # ✅ This is critical: use @modal.enter() not just __enter__
|
| 18 |
+
def init(self):
|
| 19 |
+
import whisper
|
| 20 |
+
self.model = whisper.load_model("base")
|
| 21 |
+
|
| 22 |
+
@modal.method()
|
| 23 |
+
def transcribe(self, audio_url):
|
| 24 |
+
import requests
|
| 25 |
+
|
| 26 |
+
# Download audio file
|
| 27 |
+
response = requests.get(audio_url)
|
| 28 |
+
with open("audio.wav", "wb") as f:
|
| 29 |
+
f.write(response.content)
|
| 30 |
+
|
| 31 |
+
# Run transcription
|
| 32 |
+
result = self.model.transcribe("audio.wav")
|
| 33 |
+
return result["text"]
|
| 34 |
+
|
| 35 |
+
@app.local_entrypoint()
|
| 36 |
+
def main():
|
| 37 |
+
url = "https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac"
|
| 38 |
+
|
| 39 |
+
model = WhisperModel()
|
| 40 |
+
result = model.transcribe.remote(url)
|
| 41 |
+
print(result)
|
gradio_app.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import modal
|
| 3 |
+
|
| 4 |
+
# Load your deployed Modal class
|
| 5 |
+
WhisperModel = modal.Cls.from_name("whisper-app", "WhisperModel")
|
| 6 |
+
|
| 7 |
+
# Define function to call remote transcribe
|
| 8 |
+
def transcribe_audio(url):
|
| 9 |
+
instance = WhisperModel() # creates an instance
|
| 10 |
+
return instance.transcribe.remote(url)
|
| 11 |
+
|
| 12 |
+
# Launch Gradio UI
|
| 13 |
+
gr.Interface(fn=transcribe_audio, inputs="text", outputs="text").launch()
|