BeastGokul's picture
Update app.py
8626f14 verified
import os
import gradio as gr
from llm import get_llm_feedback
from asr_api import transcribe_with_openrouter
from user_data import load_user_data, save_user_data
from phonetics import analyze_audio_phonetically, extract_phonemes
# Example minimal Gradio app setup:
PRACTICE_EXERCISES = [
{"title": "Basic Vowels", "text": "The cat sat on the mat."},
{"title": "R Sound", "text": "The red robin ran around the river."},
{"title": "TH Sounds", "text": "I think these three things are worth it."},
{"title": "L vs R", "text": "The light rain falls along the lake."},
{"title": "V vs W", "text": "We very much want to visit the west village."},
{"title": "Short Phrases", "text": "Excuse me. Thank you. I'm sorry. Nice to meet you."}
]
def process_audio(audio, ref_text):
if not audio:
return "No audio recorded", "Please record your pronunciation first."
feedback, transcription = get_llm_feedback(audio, None, ref_text, transcribe_func=transcribe_with_openrouter)
return transcription, feedback
def main():
with gr.Blocks(title="ESL Pronunciation Coach - Advanced") as demo:
user_id = gr.State("default")
gr.Markdown("# 🗣️ Advanced Pronunciation Coach")
with gr.Tab("Practice"):
with gr.Row():
with gr.Column(scale=2):
exercise_dropdown = gr.Dropdown(
choices=[ex["title"] for ex in PRACTICE_EXERCISES],
label="Select Practice Exercise",
value=PRACTICE_EXERCISES[0]["title"]
)
reference_text = gr.Textbox(
label="Practice Text (Read This Aloud)",
value=PRACTICE_EXERCISES[0]["text"],
lines=2
)
def update_reference_text(exercise_title):
for ex in PRACTICE_EXERCISES:
if ex["title"] == exercise_title:
return ex["text"]
return ""
exercise_dropdown.change(update_reference_text, exercise_dropdown, reference_text)
audio_input = gr.Audio(label="Record your pronunciation", type="filepath", format="wav", show_label=True)
submit_btn = gr.Button("Get Feedback", variant="primary")
with gr.Column(scale=3):
transcription_output = gr.Textbox(label="Your Speech (Transcribed)", lines=2)
feedback_output = gr.Textbox(label="Pronunciation Feedback", lines=6)
submit_btn.click(
process_audio,
inputs=[audio_input, reference_text],
outputs=[transcription_output, feedback_output]
)
demo.launch()
if __name__ == "__main__":
main()