jsbeaudry commited on
Commit
0493d0d
Β·
verified Β·
1 Parent(s): 5bf7330

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -14
app.py CHANGED
@@ -1,23 +1,42 @@
1
- import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # Load the Whisper pipeline from Hugging Face
5
- pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=-1) # use device=0 for GPU
 
 
6
 
7
  # Transcription function
8
  def transcribe(audio_path):
9
- print("Transcribing:", audio_path)
 
10
  result = pipe(audio_path)
11
  return result["text"]
12
 
13
- # Gradio interface
14
- app = gr.Interface(
15
- fn=transcribe,
16
- inputs=gr.Audio(source="microphone", type="filepath"),
17
- outputs="text",
18
- title="Whisper Speech Recognition",
19
- description="Record your voice and transcribe it using Whisper from Hugging Face."
20
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- # Run the app
23
- app.launch()
 
 
1
+
2
  from transformers import pipeline
3
+ import gradio as gr
4
 
5
+ # Load Whisper model
6
+ print("Loading model...")
7
+ pipe = pipeline(model="jsbeaudry/whisper-medium-oswald")
8
+ print("Model loaded successfully.")
9
 
10
  # Transcription function
11
  def transcribe(audio_path):
12
+ if audio_path is None:
13
+ return "Please upload or record an audio file first."
14
  result = pipe(audio_path)
15
  return result["text"]
16
 
17
+ # Build Gradio interface
18
+ def create_interface():
19
+ with gr.Blocks(title="Whisper Medium - Haitian Creole") as demo:
20
+ gr.Markdown("# πŸŽ™οΈ Whisper Medium Creole ASR")
21
+ gr.Markdown(
22
+ "Upload an audio file or record your voice in Haitian Creole. "
23
+ "Then click **Transcribe** to see the result."
24
+ )
25
+
26
+ with gr.Row():
27
+ with gr.Column():
28
+ audio_input = gr.Audio(source="upload", type="filepath", label="🎧 Upload Audio")
29
+ audio_input2 = gr.Audio(source="microphone", type="filepath", label="🎀 Record Audio")
30
+ with gr.Column():
31
+ transcribe_button = gr.Button("πŸ” Transcribe")
32
+ output_text = gr.Textbox(label="πŸ“ Transcribed Text", lines=4)
33
+
34
+
35
+ transcribe_button.click(fn=transcribe, inputs=audio_input, outputs=output_text)
36
+ transcribe_button.click(fn=transcribe, inputs=audio_input2, outputs=output_text)
37
+
38
+ return demo
39
 
40
+ if __name__ == "__main__":
41
+ interface = create_interface()
42
+ interface.launch()