Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,76 @@
|
|
|
|
|
| 1 |
import spaces
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
)
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 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 |
|
| 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 |
)
|
| 22 |
|
| 23 |
+
# ट्रांसक्रिप्शन जनरेट करें
|
| 24 |
+
result = pipe(audio, generate_kwargs={"language": "hindi"})
|
| 25 |
+
text_output = result["text"].strip()
|
| 26 |
|
| 27 |
+
# डाउनलोड के लिए .txt फ़ाइल बनाना
|
| 28 |
+
file_path = "transcription.txt"
|
| 29 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 30 |
+
f.write(text_output)
|
| 31 |
|
| 32 |
+
return text_output, file_path
|
| 33 |
+
|
| 34 |
+
custom_css = """
|
| 35 |
+
footer {visibility: hidden}
|
| 36 |
+
.gradio-container {background-color: #fcfcfc}
|
| 37 |
+
#header {text-align: center; margin-bottom: 20px}
|
| 38 |
+
"""
|
| 39 |
|
| 40 |
+
with gr.Blocks(title="IndicWhisper Collabora GPU") as demo:
|
| 41 |
+
gr.HTML("<div id='header'><h1>🎙️ Hindi Whisper (Collabora v2 - ZeroGPU)</h1></div>")
|
| 42 |
+
|
| 43 |
+
with gr.Row():
|
| 44 |
+
with gr.Column():
|
| 45 |
+
audio_input = gr.Audio(
|
| 46 |
+
sources=["microphone", "upload"],
|
| 47 |
+
type="filepath",
|
| 48 |
+
label="ऑडियो रिकॉर्ड करें या अपलोड करें"
|
| 49 |
+
)
|
| 50 |
+
submit_btn = gr.Button("अनुवाद करें (Transcribe)", variant="primary")
|
| 51 |
+
|
| 52 |
+
with gr.Column():
|
| 53 |
+
output_text = gr.Textbox(
|
| 54 |
+
label="Transcription Output",
|
| 55 |
+
lines=10,
|
| 56 |
+
placeholder="आपका टेक्स्ट यहाँ दिखाई देगा..."
|
| 57 |
+
)
|
| 58 |
+
# डाउनलोड लिंक के लिए Gradio का File कंपोनेंट
|
| 59 |
+
download_file = gr.File(
|
| 60 |
+
label="टैक्स्ट फ़ाइल डाउनलोड करें",
|
| 61 |
+
visible=True
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
gr.Markdown("""
|
| 65 |
+
---
|
| 66 |
+
**सुझाव:** यहाँ से प्राप्त आउटपुट को कॉपी करें या फ़ाइल डाउनलोड करके अपने **Gemini Gem** में पेस्ट करें ताकि **पञ्चमाक्षर नियमों** (ङ्, ञ्, ण्, न्, म्) के अनुसार शुद्धिकरण किया जा सके।
|
| 67 |
+
""")
|
| 68 |
+
|
| 69 |
+
submit_btn.click(
|
| 70 |
+
fn=transcribe_hindi,
|
| 71 |
+
inputs=audio_input,
|
| 72 |
+
outputs=[output_text, download_file]
|
| 73 |
+
)
|
| 74 |
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
demo.launch(css=custom_css)
|