| | import gradio as gr |
| | import requests |
| | import os |
| |
|
| | API_URL = os.getenv('API_URL') |
| | ACCESS_KEY = os.getenv('ACCESS_KEY') |
| |
|
| |
|
| | mapping_style_en = { |
| | "Close, friendly": "Gần gũi, thân thiện", |
| | "Short, concise": "Ngắn gọn, xúc tích", |
| | "Emotions": "Nhiều cảm xúc", |
| | } |
| |
|
| |
|
| | |
| | def generate_comment( |
| | title, |
| | style, |
| | content, |
| | bodyLanguage, |
| | facialEyeContact, |
| | voice, |
| | pronunciation, |
| | fluency |
| | ): |
| | payload = { |
| | "title": title, |
| | "style": mapping_style_en.get(style, style), |
| | "content": content, |
| | "bodyLanguage": bodyLanguage, |
| | "facialEyeContact": facialEyeContact, |
| | "voice": voice, |
| | "pronunciation": pronunciation, |
| | "fluency": fluency |
| | } |
| | headers = { |
| | "accept": "application/json", |
| | "access-key": ACCESS_KEY, |
| | "Content-Type": "application/json", |
| | } |
| | resp = requests.post(API_URL, headers=headers, json=payload) |
| | if resp.ok: |
| | return resp.json().get("data", {}).get("vietnamese", "No comment") |
| | return f"Error {resp.status_code}: {resp.text}" |
| |
|
| |
|
| | |
| | base_choices = [ |
| | "1 - Needs Work (Hard to follow or lacks structure)", |
| | "2 - Good (Clear but simple structure or idea)", |
| | "3 - Excellent (Clear, well-organized, logical structure, and interesting ideas)", |
| | ] |
| |
|
| | content_choices = base_choices |
| | body_language_choices = [ |
| | "1 - Needs Work (No hand gestures or distracting movements)", |
| | "2 - Good (Student sometimes uses hand gestures appropriately)", |
| | "3 - Excellent (Student uses hand gestures confidently to support message)", |
| | ] |
| | facial_eye_contact_choices = [ |
| | "1 - Needs Work (Looks away from camera (e.g., down or to the side), no expression)", |
| | "2 - Good (Sometimes looks at camera, with some expression)", |
| | "3 - Excellent (Student looks directly at camera, with appropriate facial expression)", |
| | ] |
| |
|
| | voice_choices = [ |
| | "1 - Needs Work (Too quiet, flat or hard to hear)", |
| | "2 - Good (Mostly clear and loud)", |
| | "3 - Excellent (Clear, loud, varied tone)", |
| | ] |
| | pronunciation_choices = [ |
| | "1 - Needs Work (Hard to understand, many pronunciation mistakes)", |
| | "2 - Good (Mostly clear, some errors)", |
| | "3 - Excellent (Easy to understand, correct pronunciation)", |
| | ] |
| |
|
| | fluency_choices = [ |
| | "1 - Needs Work (Frequent pauses, hard to follow)", |
| | "2 - Good (Some hesitation or uneven pace)", |
| | "3 - Excellent (Speaks smoothly, natural pace, few pauses or fillers)", |
| | ] |
| |
|
| | with gr.Blocks(gr.themes.Origin()) as demo: |
| | with gr.Row(): |
| | with gr.Column(): |
| | with gr.Group(): |
| | title = gr.Radio(["Cô", "Thầy"], label="Title", value="Cô") |
| | with gr.Group(): |
| | style = gr.Radio(["Short, concise", "Close, friendly"], label="Writing tone", value="Short, concise") |
| | with gr.Group(): |
| | content = gr.Radio(content_choices, label="Content (incl. Structure)", value=content_choices[1]) |
| | with gr.Group(): |
| | voice = gr.Radio(voice_choices, label="Voice", value=voice_choices[1]) |
| | with gr.Group(): |
| | pronunciation = gr.Radio(pronunciation_choices, label="Pronunciation", value=pronunciation_choices[1]) |
| | with gr.Column(): |
| | with gr.Group(): |
| | bodyLanguage = gr.Radio(body_language_choices, label="Body Language", value=body_language_choices[1]) |
| | with gr.Group(): |
| | facialEyeContact = gr.Radio(facial_eye_contact_choices, label="Facial Expression + Eye Contact", value=facial_eye_contact_choices[1]) |
| | with gr.Group(): |
| | fluency = gr.Radio(fluency_choices, label="Fluency", value=fluency_choices[1]) |
| | with gr.Column(): |
| | gen_btn = gr.Button("Generate comment") |
| | output = gr.Textbox(label="Teacher’s Comment", lines=5) |
| | gen_btn.click( |
| | generate_comment, |
| | [title, style, content, bodyLanguage, facialEyeContact, voice, pronunciation, fluency], |
| | output, |
| | ) |
| |
|
| | demo.launch(server_name="0.0.0.0") |
| |
|