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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -1,28 +1,37 @@
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,7 +40,7 @@ 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,6 +57,7 @@ with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
48
  lines=10,
49
  placeholder="आपका टेक्स्ट यहाँ दिखाई देगा..."
50
  )
 
51
  download_file = gr.File(
52
  label="टैक्स्ट फ़ाइल डाउनलोड करें",
53
  visible=True
@@ -55,7 +65,7 @@ with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
55
 
56
  gr.Markdown("""
57
  ---
58
- **सुझाव:** यहाँ से प्राप्त आउटपुट को कॉपी करें और अपने **Gemini Gem** में पेस्ट करें ताकि **पञ्चमाक्षर नियमों** (ङ्, ञ्, ण्, न्, म्) के अनुसार शुद्धिकरण किया जा सके।
59
  """)
60
 
61
  submit_btn.click(
 
1
  import gradio as gr
2
  import spaces
3
+ import torch
4
+ from transformers import pipeline
5
+ import os
6
 
7
+ # कोलाब वाले मॉडल का मूल आधिकारिक PyTorch वर्शन (Transformers के लिए)
8
+ MODEL_ID = "collabora/whisper-large-v2-hindi"
9
 
10
  @spaces.GPU(duration=120)
11
  def transcribe_hindi(audio):
12
  if audio is None:
13
  return "कृपया ऑडियो प्रदान करें।", None
14
 
15
+ # आधिकारिक 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, # बड़े ऑडियो को पृष्ठभूमि में 30-30 सेकंड के टुकड़ों में बांटेगा
22
+ batch_size=8 # GPU की समानांतर क्षमता का उपयोग करके प्रोसेसिंग को सुपरफ़ास्ट बनाएगा
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
  """
41
 
42
  with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
43
+ gr.HTML("<div id='header'><h1>🎙️ Hindi Whisper (Collabora Pipeline - ZeroGPU)</h1></div>")
44
 
45
  with gr.Row():
46
  with gr.Column():
 
57
  lines=10,
58
  placeholder="आपका टेक्स्ट यहाँ दिखाई देगा..."
59
  )
60
+ # फ़ाइल डाउनलोड करने के लिए Gradio का आधिकारिक कंपोनेंट
61
  download_file = gr.File(
62
  label="टैक्स्ट फ़ाइल डाउनलोड करें",
63
  visible=True
 
65
 
66
  gr.Markdown("""
67
  ---
68
+ **सुझाव:** यहाँ से प्राप्त आउटपुट को कॉपी करें या फ़ाइल डाउनलोड करके अपने **Gemini Gem** में पेस्ट करें ताकि **पञ्चमाक्षर नियमों** (ङ्, ञ्, ण्, न्, म्) के अनुसार शुद्धिकरण किया जा सके।
69
  """)
70
 
71
  submit_btn.click(