File size: 1,471 Bytes
1e44bd2
e395b3d
d33dce2
73e0bb9
7843a47
d33dce2
73e0bb9
 
 
 
 
 
 
 
 
 
 
 
d33dce2
 
73e0bb9
 
 
 
d33dce2
73e0bb9
 
28251cb
73e0bb9
 
 
 
 
3e4448a
73e0bb9
3e4448a
73e0bb9
3e4448a
73e0bb9
3e4448a
73e0bb9
 
 
3e4448a
 
73e0bb9
 
1
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
36
37
38
39
40
41
42
43
44
45
46
47
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()