Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,42 @@
|
|
1 |
-
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
# Load
|
5 |
-
|
|
|
|
|
6 |
|
7 |
# Transcription function
|
8 |
def transcribe(audio_path):
|
9 |
-
|
|
|
10 |
result = pipe(audio_path)
|
11 |
return result["text"]
|
12 |
|
13 |
-
# Gradio interface
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
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()
|