import gradio as gr from transformers import pipeline # IMPORTANT: Replace this with the exact ID of your uploaded model MODEL_ID = "Akashpb13/xlsr_kurmanji_kurdish" # Assuming your model ID uses your Space's username # Load the ASR model pipeline # The pipeline handles downloading the weights and configuration. try: transcriber = pipeline( "automatic-speech-recognition", model=MODEL_ID, # device=0 # Uncomment this if you upgrade your Space to a GPU ) except Exception as e: # Fallback for error handling if the model fails to load gr.Warning(f"Failed to load model: {e}") transcriber = None # Define the prediction function def transcribe_audio(audio_file_path): if audio_file_path is None: return "Please provide an audio input." if transcriber is None: return "Error: Model failed to initialize." # Pass the local file path provided by Gradio to the pipeline result = transcriber(audio_file_path) return result["text"] # Create the Gradio interface demo = gr.Interface( fn=transcribe_audio, inputs=gr.Audio( sources=["microphone", "upload"], type="filepath", label="Kurmanji Audio Input" ), outputs=gr.Textbox(label="Kurmanji Transcription Result"), title="Kurmanji ASR Demo", description="Automatic Speech Recognition for Kurmanji using a fine-tuned Hugging Face Transformer model." ) # Launch the application demo.launch()