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" # फंक्शन के बाहर अब हम मॉडल लोड नहीं करेंगे, ताकि बूटिंग में कोई एरर न आए। @spaces.GPU(duration=120) # जरूरत पड़ने पर टाइमआउट अवधि को बढ़ाकर 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()