LG3370 commited on
Commit
1f4859d
·
verified ·
1 Parent(s): b02c19c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -22
app.py CHANGED
@@ -1,37 +1,28 @@
1
  import gradio as gr
2
  import spaces
3
- import torch
4
- from transformers import pipeline
5
- import os
6
 
7
- # आपका पसंदीदा और सटीक हिंदी मॉडल
8
- #MODEL_ID = "collabora/faster-whisper-large-v2-hindi"
9
  MODEL_ID = "collabora/faster-whisper-large-v2-hindi"
 
10
  @spaces.GPU(duration=120)
11
  def transcribe_hindi(audio):
12
  if audio is None:
13
  return "कृपया ऑडियो प्रदान करें।", None
14
 
15
- # Standard Transformers Pipeline - ZeroGPU के CUDA ड्राइवर के साथ 100% अनुकूल
16
- pipe = pipeline(
17
- "automatic-speech-recognition",
18
- model=MODEL_ID,
19
- torch_dtype=torch.float16,
20
- device="cuda",
21
- chunk_length_s=30,
22
- batch_size=8
23
- )
24
 
25
- # ट्रांसक्रिप्शन जनरेट करें
26
- result = pipe(audio, generate_kwargs={"language": "hindi"})
27
- text_output = result["text"].strip()
28
 
29
  # डाउनलोड के लिए .txt फ़ाइल बनाना
30
  file_path = "transcription.txt"
31
  with open(file_path, "w", encoding="utf-8") as f:
32
- f.write(text_output)
33
 
34
- return text_output, file_path
35
 
36
  custom_css = """
37
  footer {visibility: hidden}
@@ -40,7 +31,7 @@ footer {visibility: hidden}
40
  """
41
 
42
  with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
43
- gr.HTML("<div id='header'><h1>🎙️ Hindi Whisper (Collabora v2 - ZeroGPU)</h1></div>")
44
 
45
  with gr.Row():
46
  with gr.Column():
@@ -57,7 +48,6 @@ with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
57
  lines=10,
58
  placeholder="आपका टेक्स्ट यहाँ दिखाई देगा..."
59
  )
60
- # डाउनलोड लिंक के लिए Gradio का File कंपोनेंट
61
  download_file = gr.File(
62
  label="टैक्स्ट फ़ाइल डाउनलोड करें",
63
  visible=True
@@ -65,7 +55,7 @@ with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
65
 
66
  gr.Markdown("""
67
  ---
68
- **सुझाव:** यहाँ से प्राप्त आउटपुट को कॉपी करें या फ़ाइल डाउनलोड करके अपने **Gemini Gem** में पेस्ट करें ताकि **पञ्चमाक्षर नियमों** (ङ्, ञ्, ण्, न्, म्) के अनुसार शुद्धिकरण किया जा सके।
69
  """)
70
 
71
  submit_btn.click(
 
1
  import gradio as gr
2
  import spaces
3
+ from faster_whisper import WhisperModel
 
 
4
 
5
+ # कोलाब वाला ही मॉडल आईडी
 
6
  MODEL_ID = "collabora/faster-whisper-large-v2-hindi"
7
+
8
  @spaces.GPU(duration=120)
9
  def transcribe_hindi(audio):
10
  if audio is None:
11
  return "कृपया ऑडियो प्रदान करें।", None
12
 
13
+ # हगिंग फेस के नए CUDA ड्राइवर के लिए compute_type="float16" अनिवार्य है
14
+ model = WhisperModel(MODEL_ID, device="cuda", compute_type="float16")
 
 
 
 
 
 
 
15
 
16
+ # व्हिस्पर लार्ज मॉडल के लिए चंकिंग बैकएंड में खुद होती है
17
+ segments, info = model.transcribe(audio, language="hi", beam_size=5)
18
+ full_text = "".join([segment.text for segment in segments])
19
 
20
  # डाउनलोड के लिए .txt फ़ाइल बनाना
21
  file_path = "transcription.txt"
22
  with open(file_path, "w", encoding="utf-8") as f:
23
+ f.write(full_text.strip())
24
 
25
+ return full_text.strip(), file_path
26
 
27
  custom_css = """
28
  footer {visibility: hidden}
 
31
  """
32
 
33
  with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
34
+ gr.HTML("<div id='header'><h1>🎙️ Hindi Whisper (Collabora - faster_whisper)</h1></div>")
35
 
36
  with gr.Row():
37
  with gr.Column():
 
48
  lines=10,
49
  placeholder="आपका टेक्स्ट यहाँ दिखाई देगा..."
50
  )
 
51
  download_file = gr.File(
52
  label="टैक्स्ट फ़ाइल डाउनलोड करें",
53
  visible=True
 
55
 
56
  gr.Markdown("""
57
  ---
58
+ **सुझाव:** यहाँ से प्राप्त आउटपुट को कॉपी करें और अपने **Gemini Gem** में पेस्ट करें ताकि **पञ्चमाक्षर नियमों** (ङ्, ञ्, ण्, न्, म्) के अनुसार शुद्धिकरण किया जा सके।
59
  """)
60
 
61
  submit_btn.click(