Spaces:
badrex
/
Running on Zero

File size: 793 Bytes
8e73cee
 
 
 
 
f9a373a
8e73cee
 
 
 
 
 
 
 
f9a373a
8e73cee
f9a373a
8e73cee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
from transformers import pipeline
import numpy as np
import os
from huggingface_hub import login
import spaces

# Get token from Space secrets
HF_TOKEN = os.environ.get("HF_TOKEN")
if HF_TOKEN:
    login(token=HF_TOKEN)

# Load model from your private repo
MODEL_ID = "badrex/JASR"  # Change this to match your repo!
transcriber = pipeline("automatic-speech-recognition", model=MODEL_ID)

@spaces.GPU
def transcribe(audio):
    sr, y = audio
    # Convert to mono if stereo
    if y.ndim > 1:
        y = y.mean(axis=1)
    y = y.astype(np.float32)
    y /= np.max(np.abs(y))
    return transcriber({"sampling_rate": sr, "raw": y})["text"]

demo = gr.Interface(
    transcribe,
    gr.Audio(sources="microphone"),
    "text",
)

if __name__ == "__main__":
    demo.launch()