Rouhani2025 commited on
Commit
f890380
·
verified ·
1 Parent(s): c51a985

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import whisper
3
+ from transformers import pipeline
4
+
5
+ # Load Whisper model
6
+ whisper_model = whisper.load_model("base", device="cpu")
7
+
8
+ # Load the text correction model
9
+ correction_pipeline = pipeline("text2text-generation", model="tiiuae/falcon-7b-instruct", device=-1)
10
+
11
+ # Function to preprocess audio and transcribe it using Whisper
12
+ def transcribe_audio(audio_file):
13
+ transcription = whisper_model.transcribe(audio_file)
14
+ return transcription["text"]
15
+
16
+ # Function to correct grammar in text
17
+ def correct_text(raw_text):
18
+ corrected = correction_pipeline(raw_text, max_length=200, num_return_sequences=1)[0]["generated_text"]
19
+ return corrected
20
+
21
+ # Function to process the pipeline
22
+ def process_pipeline(audio_file):
23
+ raw_transcription = transcribe_audio(audio_file)
24
+ corrected_transcription = correct_text(raw_transcription)
25
+ return raw_transcription, corrected_transcription
26
+
27
+ # Gradio Interface
28
+ interface = gr.Interface(
29
+ fn=process_pipeline,
30
+ inputs=gr.Audio(type="filepath", label="Upload Audio"),
31
+ outputs=[
32
+ gr.Textbox(label="Raw Transcription"),
33
+ gr.Textbox(label="Corrected Transcription"),
34
+ ],
35
+ title="Speech Correction Demo",
36
+ description="Upload an audio file to see raw transcription and grammar-corrected output.",
37
+ )
38
+
39
+ # Launch the app
40
+ interface.launch()