mayankpuvvala commited on
Commit
53b9009
·
verified ·
1 Parent(s): ae31b88

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
4
+ import tempfile
5
+ import torchaudio
6
+
7
+ # Load Whisper for transcription
8
+ asr_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")
9
+
10
+ # Load grammar scoring model
11
+ cola_model = AutoModelForSequenceClassification.from_pretrained("textattack/roberta-base-CoLA")
12
+ cola_tokenizer = AutoTokenizer.from_pretrained("textattack/roberta-base-CoLA")
13
+ grammar_pipeline = pipeline("text-classification", model=cola_model, tokenizer=cola_tokenizer)
14
+
15
+ # Load grammar correction model
16
+ correction_pipeline = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
17
+
18
+ def process_audio(audio_file):
19
+ # Save uploaded file to temporary path
20
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
21
+ tmp.write(audio_file.read())
22
+ tmp_path = tmp.name
23
+
24
+ # Transcription
25
+ transcription = asr_pipeline(tmp_path)["text"]
26
+
27
+ # Grammar Scoring
28
+ grammar_result = grammar_pipeline(transcription)[0]
29
+ score_label = grammar_result["label"]
30
+ score_confidence = grammar_result["score"]
31
+
32
+ # Correction
33
+ corrected_text = correction_pipeline(transcription, max_length=128)[0]["generated_text"]
34
+
35
+ return transcription, f"{score_label} ({score_confidence:.2f})", corrected_text
36
+
37
+ # Gradio Interface
38
+ interface = gr.Interface(
39
+ fn=process_audio,
40
+ inputs=gr.Audio(type="file", label="Upload your .wav file"),
41
+ outputs=[
42
+ gr.Textbox(label="Transcription"),
43
+ gr.Textbox(label="Grammar Score"),
44
+ gr.Textbox(label="Grammar Correction")
45
+ ],
46
+ title="🎙️ Voice Grammar Scorer",
47
+ description="Upload your voice (WAV file). This app transcribes it, scores grammar, and suggests corrections."
48
+ )
49
+
50
+ if __name__ == "__main__":
51
+ interface.launch()