fawzanaramam commited on
Commit
2ad9e9b
Β·
verified Β·
1 Parent(s): 29727a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -14
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
- text = pipe(audio)["text"]
8
- return text
9
-
10
- iface = gr.Interface(
11
- fn=transcribe,
12
- inputs=gr.Audio(sources=["microphone","upload"], type="filepath"),
13
- outputs="text",
14
- title="Whisper Small Surah Fatiha",
15
- description="Realtime demo for Surah Fatiha speech recognition using a fine-tuned Whisper small model.",
16
- )
17
-
18
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()