masumtechnonext commited on
Commit
edd7d5a
Β·
verified Β·
1 Parent(s): e1fc5ec

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +8 -7
  2. app.py +64 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,14 @@
1
  ---
2
- title: Host Model Gra
3
- emoji: 🏒
4
- colorFrom: gray
5
- colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 6.22.0
8
- python_version: '3.12'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: host_model_gra
3
+ emoji: πŸš€
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 5.0.0
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # host_model_gra
13
+
14
+ Minimal Gradio app scaffold, ready to deploy to Hugging Face Spaces.
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+ import torch
5
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
6
+
7
+ MODEL_ID = os.environ.get("HF_ASR_MODEL", "masumtechnonext/wav2vec2-arabic-letter-verifier")
8
+ HF_TOKEN = os.environ.get("HF_TOKEN")
9
+
10
+ processor = Wav2Vec2Processor.from_pretrained(MODEL_ID, token=HF_TOKEN)
11
+ model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID, token=HF_TOKEN)
12
+ model.eval()
13
+
14
+
15
+ def transcribe(audio):
16
+ if audio is None:
17
+ return "", "Record or upload audio first."
18
+
19
+ sample_rate, waveform = audio
20
+ waveform = torch.tensor(waveform, dtype=torch.float32)
21
+ if waveform.ndim > 1:
22
+ waveform = waveform.mean(dim=-1)
23
+
24
+ inputs = processor(
25
+ waveform.numpy(),
26
+ sampling_rate=sample_rate,
27
+ return_tensors="pt",
28
+ padding=True,
29
+ )
30
+
31
+ with torch.no_grad():
32
+ logits = model(inputs.input_values).logits
33
+
34
+ predicted_ids = torch.argmax(logits, dim=-1)
35
+ transcription = processor.batch_decode(predicted_ids)[0].strip()
36
+ return transcription
37
+
38
+
39
+ def verify(audio, expected_letter):
40
+ transcription = transcribe(audio)
41
+ if not expected_letter:
42
+ return transcription, "Enter an expected letter to verify."
43
+
44
+ is_match = transcription.strip() == expected_letter.strip()
45
+ verdict = "βœ… Match" if is_match else "❌ No match"
46
+ return transcription, verdict
47
+
48
+
49
+ demo = gr.Interface(
50
+ fn=verify,
51
+ inputs=[
52
+ gr.Audio(sources=["microphone", "upload"], type="numpy", label="Speak the letter"),
53
+ gr.Textbox(label="Expected letter (optional)"),
54
+ ],
55
+ outputs=[
56
+ gr.Textbox(label="Transcription"),
57
+ gr.Textbox(label="Verification"),
58
+ ],
59
+ title="Arabic Letter Verifier",
60
+ description=f"Model: {MODEL_ID}",
61
+ )
62
+
63
+ if __name__ == "__main__":
64
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ torch
3
+ transformers