amedcj commited on
Commit
b445310
Β·
verified Β·
1 Parent(s): d15ddb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -5,7 +5,7 @@ import os
5
 
6
  print("πŸš€ Starting Kurmanji ASR application...")
7
 
8
- # Define MODEL_ID. Assuming it's in the root of the Space, use the Space ID.
9
  MODEL_ID = "."
10
 
11
  # --- MODEL LOADING FUNCTION ---
@@ -15,16 +15,18 @@ def load_asr_model():
15
  try:
16
  print("πŸ“₯ Loading ASR pipeline...")
17
 
 
18
  asr = pipeline(
19
  "automatic-speech-recognition",
20
  model=MODEL_ID,
21
- chunk_length_s=5, # Reduced for stability
22
- stride_length_s=(1, 1), # Reduced for stability
23
- device="cpu", # Corrected device specification
24
- low_cpu_mem_usage=True, # Added for memory efficiency
25
- # Ensure this line ends with a comma (,) and the parenthesis is closed on the next line
26
- generate_kwargs={"language": "ku", "task": "transcribe"}
27
- ) # <-- ENSURE THIS CLOSING PARENTHESIS IS HERE
 
28
  print("βœ… ASR pipeline created successfully!")
29
  except Exception as e:
30
  print(f"❌ Error loading ASR model: {e}")
@@ -36,7 +38,6 @@ load_asr_model() # Load the model at start
36
  # --- TRANSCRIPTION FUNCTION ---
37
  def transcribe(audio_file):
38
  print("=== ASR Function Called ===")
39
- print(f"Audio file: {audio_file}")
40
 
41
  try:
42
  if audio_file is None:
@@ -45,10 +46,13 @@ def transcribe(audio_file):
45
  if asr is None:
46
  return "Model nehatiye barkirin. / ASR model not loaded properly."
47
 
48
- print("🎡 Processing audio file...")
49
 
 
50
  result = asr(audio_file)
51
- transcription = result["text"].strip() # Clean the output
 
 
52
 
53
  print(f"βœ… Transcription completed: {transcription}")
54
  return transcription
@@ -86,5 +90,4 @@ demo = gr.Interface(
86
  # --- LAUNCH ---
87
  print("πŸš€ Launching Gradio app...")
88
  if __name__ == "__main__":
89
- # FIX APPLIED HERE: Removed 'ssr_mode=False'
90
  demo.launch()
 
5
 
6
  print("πŸš€ Starting Kurmanji ASR application...")
7
 
8
+ # Define MODEL_ID: Set to '.' because model files are in the same Space repository.
9
  MODEL_ID = "."
10
 
11
  # --- MODEL LOADING FUNCTION ---
 
15
  try:
16
  print("πŸ“₯ Loading ASR pipeline...")
17
 
18
+ # Use the pipeline's auto-loading feature
19
  asr = pipeline(
20
  "automatic-speech-recognition",
21
  model=MODEL_ID,
22
+ # Optimized for limited resources/speedβ€”you may need to adjust these values
23
+ chunk_length_s=5, # Smaller chunks require less memory
24
+ stride_length_s=(1, 1), # Reduced stride for less overlap
25
+ device="cpu", # Explicitly use CPU (important for free tier)
26
+ low_cpu_mem_usage=True, # Saves RAM during model initialization
27
+ # VITAL FOR QUALITY: Force the model to use the Kurdish language (ku)
28
+ generate_kwargs={"language": "ku", "task": "transcribe"}
29
+ )
30
  print("βœ… ASR pipeline created successfully!")
31
  except Exception as e:
32
  print(f"❌ Error loading ASR model: {e}")
 
38
  # --- TRANSCRIPTION FUNCTION ---
39
  def transcribe(audio_file):
40
  print("=== ASR Function Called ===")
 
41
 
42
  try:
43
  if audio_file is None:
 
46
  if asr is None:
47
  return "Model nehatiye barkirin. / ASR model not loaded properly."
48
 
49
+ print(f"🎡 Processing audio file: {audio_file}")
50
 
51
+ # Transcribe the audio
52
  result = asr(audio_file)
53
+
54
+ # Post-processing: clean output and remove leading/trailing spaces
55
+ transcription = result["text"].strip()
56
 
57
  print(f"βœ… Transcription completed: {transcription}")
58
  return transcription
 
90
  # --- LAUNCH ---
91
  print("πŸš€ Launching Gradio app...")
92
  if __name__ == "__main__":
 
93
  demo.launch()