mayankpuvvala commited on
Commit
5d66bfc
Β·
verified Β·
1 Parent(s): c64a43c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -1,8 +1,6 @@
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")
@@ -15,21 +13,16 @@ grammar_pipeline = pipeline("text-classification", model=cola_model, tokenizer=c
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
@@ -37,14 +30,18 @@ def process_audio(audio_file):
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__":
 
1
  import gradio as gr
2
  import torch
3
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
 
 
4
 
5
  # Load Whisper for transcription
6
  asr_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")
 
13
  # Load grammar correction model
14
  correction_pipeline = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
15
 
16
+ def process_audio(audio_path):
17
+ # Transcribe
18
+ transcription = asr_pipeline(audio_path)["text"]
 
 
19
 
20
+ # Score grammar
 
 
 
21
  grammar_result = grammar_pipeline(transcription)[0]
22
  score_label = grammar_result["label"]
23
  score_confidence = grammar_result["score"]
24
 
25
+ # Suggest correction
26
  corrected_text = correction_pipeline(transcription, max_length=128)[0]["generated_text"]
27
 
28
  return transcription, f"{score_label} ({score_confidence:.2f})", corrected_text
 
30
  # Gradio Interface
31
  interface = gr.Interface(
32
  fn=process_audio,
33
+ inputs=gr.Audio(
34
+ source="microphone", # enables both mic recording and upload
35
+ type="filepath",
36
+ label="🎀 Record or Upload Audio (.wav)"
37
+ ),
38
  outputs=[
39
+ gr.Textbox(label="πŸ“ Transcription"),
40
+ gr.Textbox(label="βœ… Grammar Score"),
41
+ gr.Textbox(label="✍️ Suggested Correction")
42
  ],
43
  title="πŸŽ™οΈ Voice Grammar Scorer",
44
+ description="Record or upload your voice (.wav). This app transcribes it, scores grammar, and suggests corrections."
45
  )
46
 
47
  if __name__ == "__main__":