Download appX.py from LG3370/Hindi-Transcriber-Collabora-Whisper: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/LG3370/Hindi-Transcriber-Collabora-Whisper/resolve/b38ca8ab7cdc203d952b02d33ca12ee5996ab09d/appX.py
- Command line
-
hf download hf://spaces/LG3370/Hindi-Transcriber-Collabora-Whisper@b38ca8ab7cdc203d952b02d33ca12ee5996ab09d/appX.py
-
curl -L -o appX.py https://huggingface.co/spaces/LG3370/Hindi-Transcriber-Collabora-Whisper/resolve/b38ca8ab7cdc203d952b02d33ca12ee5996ab09d/appX.py
1.49 kB
| import gradio as gr | |
| from faster_whisper import WhisperModel | |
| import spaces | |
| #MODEL_ID = "Systran/faster-whisper-large-v3" | |
| MODEL_ID = "collabora/whisper-large-v2-hindi" | |
| # फंक्शन के बाहर अब हम मॉडल लोड नहीं करेंगे, ताकि बूटिंग में कोई एरर न आए। | |
| # जरूरत पड़ने पर टाइमआउट अवधि को बढ़ाकर 120 सेकंड किया | |
| def transcribe_hindi(audio_path): | |
| if audio_path is None: | |
| return "कृपया कोई ऑडियो फ़ाइल अपलोड करें।" | |
| # सुधार: मॉडल को सीधे फंक्शन के अंदर CUDA मोड और float16 के साथ लोड करें | |
| # ZeroGPU इस पूरे फंक्शन को सीधे GPU कंटेनर में चलाएगा | |
| print("Loading model inside ZeroGPU...") | |
| model = WhisperModel(MODEL_ID, device="cuda") #, compute_type="float32") | |
| print("Transcribing...") | |
| segments, info = model.transcribe(audio_path, beam_size=5, language="hi") | |
| text = "".join([segment.text for segment in segments]) | |
| return text | |
| demo = gr.Interface( | |
| fn=transcribe_hindi, | |
| inputs=gr.Audio(type="filepath"), | |
| outputs="text", | |
| title="Hindi Audio Transcription via ZeroGPU", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |