Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -137,12 +137,15 @@ def run_sentence_evaluation(audio_input, reference_transcript):
|
|
| 137 |
return 0, "Error", error_msg, None
|
| 138 |
|
| 139 |
|
| 140 |
-
# --- 3. INTERFAZ DE GRADIO CON PESTA脩AS ---
|
|
|
|
| 141 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 142 |
gr.Markdown("# 馃嚞馃嚙 AI English Speaking Practice & Assessment")
|
|
|
|
| 143 |
with gr.Tabs():
|
| 144 |
-
# --- PESTA脩A 1: CHAT AI ---
|
| 145 |
with gr.TabItem("Pr谩ctica Conversacional (Chat AI)"):
|
|
|
|
| 146 |
with gr.Row():
|
| 147 |
with gr.Column(scale=2):
|
| 148 |
chatbot = gr.Chatbot(value=[(None, "Hi there! I'm Alex. How are you doing today?")], label="Conversation with your AI Tutor")
|
|
@@ -152,14 +155,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 152 |
history = gr.State([])
|
| 153 |
audio_in_chat.stop_recording(fn=chat_interaction, inputs=[audio_in_chat, history], outputs=[chatbot, history, feedback_en_out, feedback_es_out])
|
| 154 |
|
| 155 |
-
# --- PESTA脩A 2: EVALUACI脫N POR FRASE ---
|
| 156 |
with gr.TabItem("Evaluaci贸n por Frase"):
|
| 157 |
TONGUE_TWISTERS = ["Peter Piper picked a peck of pickled peppers.", "She sells seashells by the seashore.", "How much wood would a woodchuck chuck if a woodchuck could chuck wood?", "Betty Botter bought some butter but she said the butter鈥檚 bitter.", "A proper copper coffee pot."]
|
| 158 |
gr.Markdown("Choose a tongue twister or write your own sentence. Record yourself, and our AI examiner will provide a detailed diagnostic report.")
|
| 159 |
tongue_twister_selector = gr.Dropdown(choices=TONGUE_TWISTERS, label="Or Choose a Tongue Twister to Practice")
|
|
|
|
| 160 |
with gr.Row():
|
| 161 |
with gr.Column(scale=1):
|
| 162 |
-
# --- CORRECCI脫N: Par谩metros completos en lugar de '...' ---
|
| 163 |
audio_in_sentence = gr.Audio(sources=["microphone"], type="numpy", label="1. Record Your Voice")
|
| 164 |
text_in_sentence = gr.Textbox(lines=3, label="2. Reference Sentence", value=TONGUE_TWISTERS[0])
|
| 165 |
submit_btn_sentence = gr.Button("Get Assessment", variant="primary")
|
|
@@ -169,11 +172,26 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 169 |
score_out_sentence = gr.Number(label="Overall Score (0-100)", interactive=False)
|
| 170 |
level_out_sentence = gr.Textbox(label="Estimated CEFR Level", interactive=False)
|
| 171 |
holistic_feedback_out_sentence = gr.Markdown(label="Examiner's Feedback")
|
|
|
|
| 172 |
gr.Markdown("--- \n ### Detailed Word-by-Word Analysis")
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
def update_text(choice): return gr.Textbox(value=choice)
|
| 175 |
tongue_twister_selector.change(fn=update_text, inputs=tongue_twister_selector, outputs=text_in_sentence)
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
if __name__ == "__main__":
|
| 179 |
if not api_key_found: print("\nFATAL: OpenAI API key not found.")
|
|
|
|
| 137 |
return 0, "Error", error_msg, None
|
| 138 |
|
| 139 |
|
| 140 |
+
# --- 3. INTERFAZ DE GRADIO CON PESTA脩AS (Con la tabla corregida) ---
|
| 141 |
+
|
| 142 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 143 |
gr.Markdown("# 馃嚞馃嚙 AI English Speaking Practice & Assessment")
|
| 144 |
+
|
| 145 |
with gr.Tabs():
|
| 146 |
+
# --- PESTA脩A 1: CHAT AI (sin cambios) ---
|
| 147 |
with gr.TabItem("Pr谩ctica Conversacional (Chat AI)"):
|
| 148 |
+
# ... (todo el c贸digo de la interfaz del chatbot se mantiene igual)
|
| 149 |
with gr.Row():
|
| 150 |
with gr.Column(scale=2):
|
| 151 |
chatbot = gr.Chatbot(value=[(None, "Hi there! I'm Alex. How are you doing today?")], label="Conversation with your AI Tutor")
|
|
|
|
| 155 |
history = gr.State([])
|
| 156 |
audio_in_chat.stop_recording(fn=chat_interaction, inputs=[audio_in_chat, history], outputs=[chatbot, history, feedback_en_out, feedback_es_out])
|
| 157 |
|
| 158 |
+
# --- PESTA脩A 2: EVALUACI脫N POR FRASE (Con la tabla corregida) ---
|
| 159 |
with gr.TabItem("Evaluaci贸n por Frase"):
|
| 160 |
TONGUE_TWISTERS = ["Peter Piper picked a peck of pickled peppers.", "She sells seashells by the seashore.", "How much wood would a woodchuck chuck if a woodchuck could chuck wood?", "Betty Botter bought some butter but she said the butter鈥檚 bitter.", "A proper copper coffee pot."]
|
| 161 |
gr.Markdown("Choose a tongue twister or write your own sentence. Record yourself, and our AI examiner will provide a detailed diagnostic report.")
|
| 162 |
tongue_twister_selector = gr.Dropdown(choices=TONGUE_TWISTERS, label="Or Choose a Tongue Twister to Practice")
|
| 163 |
+
|
| 164 |
with gr.Row():
|
| 165 |
with gr.Column(scale=1):
|
|
|
|
| 166 |
audio_in_sentence = gr.Audio(sources=["microphone"], type="numpy", label="1. Record Your Voice")
|
| 167 |
text_in_sentence = gr.Textbox(lines=3, label="2. Reference Sentence", value=TONGUE_TWISTERS[0])
|
| 168 |
submit_btn_sentence = gr.Button("Get Assessment", variant="primary")
|
|
|
|
| 172 |
score_out_sentence = gr.Number(label="Overall Score (0-100)", interactive=False)
|
| 173 |
level_out_sentence = gr.Textbox(label="Estimated CEFR Level", interactive=False)
|
| 174 |
holistic_feedback_out_sentence = gr.Markdown(label="Examiner's Feedback")
|
| 175 |
+
|
| 176 |
gr.Markdown("--- \n ### Detailed Word-by-Word Analysis")
|
| 177 |
+
|
| 178 |
+
# --- AJUSTE CLAVE: Especificamos el tipo de dato para cada columna ---
|
| 179 |
+
word_analysis_out_sentence = gr.DataFrame(
|
| 180 |
+
headers=["Reference Word", "Spoken Word", "Score (0-100)", "Feedback (English)", "Feedback (Espa帽ol)", "Reference Audio"],
|
| 181 |
+
# Le decimos a Gradio que la 煤ltima columna es de tipo 'audio'
|
| 182 |
+
datatype=["str", "str", "number", "str", "str", "audio"],
|
| 183 |
+
label="Phonetic Breakdown",
|
| 184 |
+
wrap=True
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
def update_text(choice): return gr.Textbox(value=choice)
|
| 188 |
tongue_twister_selector.change(fn=update_text, inputs=tongue_twister_selector, outputs=text_in_sentence)
|
| 189 |
+
|
| 190 |
+
submit_btn_sentence.click(
|
| 191 |
+
fn=run_sentence_evaluation,
|
| 192 |
+
inputs=[audio_in_sentence, text_in_sentence],
|
| 193 |
+
outputs=[score_out_sentence, level_out_sentence, holistic_feedback_out_sentence, word_analysis_out_sentence]
|
| 194 |
+
)
|
| 195 |
|
| 196 |
if __name__ == "__main__":
|
| 197 |
if not api_key_found: print("\nFATAL: OpenAI API key not found.")
|