Sabbir772 commited on
Commit
cd2510b
·
verified ·
1 Parent(s): 4330dcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py CHANGED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # ==============================
5
+ # CONFIG
6
+ # ==============================
7
+ MODEL_PATH = "Sabbir772/BNWCH"
8
+ LANGUAGE = "bn" # Bengali
9
+ TASK = "transcribe"
10
+
11
+ # ==============================
12
+ # LOAD MODEL
13
+ # ==============================
14
+ print(f"🔍 Loading model from {MODEL_PATH} ...")
15
+ pipe = pipeline(
16
+ task="automatic-speech-recognition",
17
+ model=MODEL_PATH,
18
+ tokenizer=MODEL_PATH,
19
+ chunk_length_s=30, # You can tune this for performance
20
+ device=-1 # Use CPU on Spaces unless GPU is enabled
21
+ )
22
+ pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(
23
+ language=LANGUAGE, task=TASK
24
+ )
25
+ print("✅ Model loaded successfully!\n")
26
+
27
+ # ==============================
28
+ # DEFINE INFERENCE FUNCTION
29
+ # ==============================
30
+ def transcribe(audio):
31
+ """Takes an audio file (tuple from Gradio) and returns transcription."""
32
+ if audio is None:
33
+ return "No audio provided."
34
+ # Gradio passes (sample_rate, data)
35
+ sr, data = audio
36
+ result = pipe(data)["text"]
37
+ return result.strip()
38
+
39
+ # ==============================
40
+ # DEFINE GRADIO INTERFACE
41
+ # ==============================
42
+ title = "Bangla Whisper ASR (Chittagong Dialect)"
43
+ description = (
44
+ "🎙️ Upload or record audio to transcribe Bangla (Chittagong dialect) speech "
45
+ "using fine-tuned Whisper model. <br><br>"
46
+ "Model: **Sabbir772/BNWCH**"
47
+ )
48
+
49
+ demo = gr.Interface(
50
+ fn=transcribe,
51
+ inputs=gr.Audio(sources=["microphone", "upload"], type="numpy", label="🎧 Input Audio"),
52
+ outputs=gr.Textbox(label="📝 Transcription", placeholder="Model output will appear here..."),
53
+ title=title,
54
+ description=description,
55
+ allow_flagging="never",
56
+ )
57
+
58
+ # ==============================
59
+ # LAUNCH APP
60
+ # ==============================
61
+ if __name__ == "__main__":
62
+ demo.launch()