Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,75 @@
|
|
1 |
-
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
pipe = pipeline(model="fawzanaramam/Whisper-Small-Finetuned-on-Surah-Fatiha") # change to "your-username/the-name-you-picked"
|
5 |
|
6 |
def transcribe(audio):
|
7 |
-
|
8 |
-
return text
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the fine-tuned Whisper model
|
5 |
+
pipe = pipeline(model="fawzanaramam/Whisper-Small-Finetuned-on-Surah-Fatiha")
|
6 |
|
|
|
7 |
|
8 |
def transcribe(audio):
|
9 |
+
"""Transcribes the given audio using Whisper"""
|
10 |
+
return pipe(audio)["text"]
|
11 |
+
|
12 |
+
|
13 |
+
def save_transcription(text):
|
14 |
+
"""Creates a downloadable text file for the transcription"""
|
15 |
+
file_path = "transcription.txt"
|
16 |
+
with open(file_path, "w") as f:
|
17 |
+
f.write(text)
|
18 |
+
return file_path
|
19 |
+
|
20 |
+
|
21 |
+
# UI Layout
|
22 |
+
with gr.Blocks(
|
23 |
+
css="""
|
24 |
+
h1 {
|
25 |
+
font-size: 32px;
|
26 |
+
font-weight: bold;
|
27 |
+
text-align: center;
|
28 |
+
}
|
29 |
+
h2, h3 {
|
30 |
+
font-size: 26px;
|
31 |
+
font-weight: bold;
|
32 |
+
}
|
33 |
+
.gr-button {
|
34 |
+
font-size: 18px;
|
35 |
+
font-weight: bold;
|
36 |
+
}
|
37 |
+
.gr-textbox {
|
38 |
+
font-size: 18px;
|
39 |
+
}
|
40 |
+
"""
|
41 |
+
) as demo:
|
42 |
+
|
43 |
+
gr.Markdown("# π Whisper Small - Surah Fatiha Transcription")
|
44 |
+
gr.Markdown(
|
45 |
+
"Fine-tuned Whisper model for recognizing and transcribing Surah Fatiha."
|
46 |
+
)
|
47 |
+
|
48 |
+
with gr.Tab("π€ Record Audio"):
|
49 |
+
mic_input = gr.Audio(
|
50 |
+
sources=["microphone"], type="filepath", label="Record Audio"
|
51 |
+
)
|
52 |
+
transcribe_btn_1 = gr.Button("Transcribe")
|
53 |
+
output_text_1 = gr.Textbox(label="Transcription", interactive=False)
|
54 |
+
download_btn_1 = gr.File(label="Download Transcription", visible=False)
|
55 |
+
|
56 |
+
with gr.Tab("π₯ Upload Audio"):
|
57 |
+
file_input = gr.Audio(
|
58 |
+
sources=["upload"], type="filepath", label="Upload Audio File"
|
59 |
+
)
|
60 |
+
transcribe_btn_2 = gr.Button("Transcribe")
|
61 |
+
output_text_2 = gr.Textbox(label="Transcription", interactive=False)
|
62 |
+
download_btn_2 = gr.File(label="Download Transcription", visible=False)
|
63 |
+
|
64 |
+
# Function connections
|
65 |
+
transcribe_btn_1.click(fn=transcribe, inputs=mic_input, outputs=output_text_1)
|
66 |
+
transcribe_btn_2.click(fn=transcribe, inputs=file_input, outputs=output_text_2)
|
67 |
+
|
68 |
+
transcribe_btn_1.click(
|
69 |
+
fn=save_transcription, inputs=output_text_1, outputs=download_btn_1
|
70 |
+
)
|
71 |
+
transcribe_btn_2.click(
|
72 |
+
fn=save_transcription, inputs=output_text_2, outputs=download_btn_2
|
73 |
+
)
|
74 |
+
|
75 |
+
demo.launch()
|