Spaces:
badrex
/
Running on Zero

badrex commited on
Commit
8e73cee
·
1 Parent(s): 7499498

Add ASR demo

Browse files
Files changed (3) hide show
  1. README.md +6 -9
  2. app.py +32 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,13 +1,10 @@
1
  ---
2
- title: JASR
3
- emoji: 🏃
4
- colorFrom: pink
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 5.34.2
8
  app_file: app.py
9
  pinned: false
10
- short_description: Dialectal Arabic ASR
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: ASR Demo
3
+ emoji: 🎤
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 4.19.0
8
  app_file: app.py
9
  pinned: false
10
+ ---
 
 
 
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+ import os
5
+ from huggingface_hub import login
6
+
7
+ # Get token from Space secrets
8
+ HF_TOKEN = os.environ.get("HF_TOKEN")
9
+ if HF_TOKEN:
10
+ login(token=HF_TOKEN)
11
+
12
+ # Load model from your private repo
13
+ MODEL_ID = "badrex/JASR" # Change this to match your repo!
14
+ transcriber = pipeline("automatic-speech-recognition", model=MODEL_ID, use_auth_token=HF_TOKEN)
15
+
16
+ def transcribe(audio):
17
+ sr, y = audio
18
+ # Convert to mono if stereo
19
+ if y.ndim > 1:
20
+ y = y.mean(axis=1)
21
+ y = y.astype(np.float32)
22
+ y /= np.max(np.abs(y))
23
+ return transcriber({"sampling_rate": sr, "raw": y})["text"]
24
+
25
+ demo = gr.Interface(
26
+ transcribe,
27
+ gr.Audio(sources="microphone"),
28
+ "text",
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio==4.44.0
2
+ gradio-client==1.3.0
3
+ transformers>=4.36.0
4
+ torch>=2.0.0
5
+ torchaudio>=2.0.0
6
+ librosa>=0.10.1
7
+ pydantic==2.10.6