Spaces:
Sleeping
Sleeping
Mustafa Can commited on
Commit ·
4597406
1
Parent(s): c3d9b95
Add gradio app
Browse files- app.py +38 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from faster_whisper import WhisperModel
|
| 3 |
+
|
| 4 |
+
# Model choice: use smaller models for speed on M1 Pro (try "tiny" or "small")
|
| 5 |
+
MODEL_SIZE = "small"
|
| 6 |
+
|
| 7 |
+
# compute_type="int8" uses quantized weights for faster CPU inference
|
| 8 |
+
model = WhisperModel(MODEL_SIZE, device="cpu", compute_type="int8")
|
| 9 |
+
|
| 10 |
+
def transcribe(audio_path):
|
| 11 |
+
if not audio_path:
|
| 12 |
+
return ""
|
| 13 |
+
segments, info = model.transcribe(audio_path, beam_size=1, vad_filter=True)
|
| 14 |
+
text = "".join([seg.text for seg in segments])
|
| 15 |
+
return text
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=transcribe,
|
| 19 |
+
inputs=gr.Audio(source="upload", type="filepath", label="Upload audio file"),
|
| 20 |
+
outputs=gr.Textbox(label="Transcription"),
|
| 21 |
+
title="Fast Local Transcription",
|
| 22 |
+
description=("faster-whisper backend; pick model_size=" + MODEL_SIZE +
|
| 23 |
+
" for a balance of speed/accuracy."),
|
| 24 |
+
allow_flagging=False,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Expose the Gradio app variable so Spaces can detect API endpoints
|
| 28 |
+
gradio_app = iface
|
| 29 |
+
|
| 30 |
+
# Enable the request queue so the Space exposes queue-based API endpoints
|
| 31 |
+
try:
|
| 32 |
+
gradio_app = gradio_app.queue()
|
| 33 |
+
except Exception:
|
| 34 |
+
# older gradio versions may not support queue(); ignore if unavailable
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
iface.launch(server_name="0.0.0.0", share=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==6.12.0
|
| 2 |
+
faster-whisper>=0.6
|
| 3 |
+
|
| 4 |
+
# Notes: faster-whisper may require additional system dependencies (ffmpeg).
|
| 5 |
+
# On macOS (Homebrew): brew install ffmpeg
|