Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
API_URL = os.getenv('API_URL')
|
| 6 |
+
ACCESS_KEY = os.getenv('ACCESS_KEY')
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
mapping_style_en = {
|
| 10 |
+
"Close, friendly": "Gần gũi, thân thiện",
|
| 11 |
+
"Short, concise": "Ngắn gọn, xúc tích",
|
| 12 |
+
"Emotions": "Nhiều cảm xúc",
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Gọi API và trả về comment
|
| 17 |
+
def generate_comment(
|
| 18 |
+
title,
|
| 19 |
+
style,
|
| 20 |
+
content,
|
| 21 |
+
bodyLanguage,
|
| 22 |
+
facialEyeContact,
|
| 23 |
+
voice,
|
| 24 |
+
pronunciation,
|
| 25 |
+
fluency,
|
| 26 |
+
slideDesign,
|
| 27 |
+
):
|
| 28 |
+
payload = {
|
| 29 |
+
"title": title,
|
| 30 |
+
"style": mapping_style_en.get(style, style), # Chuyển đổi style sang tiếng Việt
|
| 31 |
+
"content": content,
|
| 32 |
+
"bodyLanguage": bodyLanguage,
|
| 33 |
+
"facialEyeContact": facialEyeContact,
|
| 34 |
+
"voice": voice,
|
| 35 |
+
"pronunciation": pronunciation,
|
| 36 |
+
"fluency": fluency,
|
| 37 |
+
"slideDesign": slideDesign,
|
| 38 |
+
}
|
| 39 |
+
headers = {
|
| 40 |
+
"accept": "application/json",
|
| 41 |
+
"access-key": ACCESS_KEY,
|
| 42 |
+
"Content-Type": "application/json",
|
| 43 |
+
}
|
| 44 |
+
resp = requests.post(API_URL, headers=headers, json=payload)
|
| 45 |
+
if resp.ok:
|
| 46 |
+
return resp.json().get("data", {}).get("vietnamese", "No comment")
|
| 47 |
+
return f"Error {resp.status_code}: {resp.text}"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# Các lựa chọn chung cho radio buttons
|
| 51 |
+
base_choices = [
|
| 52 |
+
"1 - Needs Work (Hard to follow or lacks structure)",
|
| 53 |
+
"2 - Good (Clear but simple structure or idea)",
|
| 54 |
+
"3 - Excellent (Clear, well-organized, logical structure, and interesting ideas)",
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
content_choices = base_choices
|
| 58 |
+
body_language_choices = [
|
| 59 |
+
"1 - Needs Work (No hand gestures or distracting movements)",
|
| 60 |
+
"2 - Good (Student sometimes uses hand gestures appropriately)",
|
| 61 |
+
"3 - Excellent (Student uses hand gestures confidently to support message)",
|
| 62 |
+
]
|
| 63 |
+
facial_eye_contact_choices = [
|
| 64 |
+
"1 - Needs Work (Looks away from camera (e.g., down or to the side), no expression)",
|
| 65 |
+
"2 - Good (Sometimes looks at camera, with some expression)",
|
| 66 |
+
"3 - Excellent (Student looks directly at camera, with appropriate facial expression)",
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
voice_choices = [
|
| 70 |
+
"1 - Needs Work (Too quiet, flat or hard to hear)",
|
| 71 |
+
"2 - Good (Mostly clear and loud)",
|
| 72 |
+
"3 - Excellent (Clear, loud, varied tone)",
|
| 73 |
+
]
|
| 74 |
+
pronunciation_choices = [
|
| 75 |
+
"1 - Needs Work (Hard to understand, many pronunciation mistakes)",
|
| 76 |
+
"2 - Good (Mostly clear, some errors)",
|
| 77 |
+
"3 - Excellent (Easy to understand, correct pronunciation)",
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
fluency_choices = [
|
| 81 |
+
"1 - Needs Work (Frequent pauses, hard to follow)",
|
| 82 |
+
"2 - Good (Some hesitation or uneven pace)",
|
| 83 |
+
"3 - Excellent (Speaks smoothly, natural pace, few pauses or fillers)",
|
| 84 |
+
]
|
| 85 |
+
slide_design_choices = [
|
| 86 |
+
"1 - Needs Work (Hard to read, messy or too much text)",
|
| 87 |
+
"2 - Good (Basic but readable, some visuals)",
|
| 88 |
+
"3 - Excellent (Clear, well-organized, visual support, not too much text)",
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
with gr.Blocks(gr.themes.Origin()) as demo:
|
| 92 |
+
gr.Markdown("## Assessment & Comment Generator")
|
| 93 |
+
with gr.Row():
|
| 94 |
+
with gr.Column():
|
| 95 |
+
with gr.Group():
|
| 96 |
+
title = gr.Radio(["Cô", "Thầy"], label="Title", value="Cô")
|
| 97 |
+
with gr.Group():
|
| 98 |
+
style = gr.Radio(["Short, concise", "Close, friendly"], label="Writing tone", value="Short, concise")
|
| 99 |
+
with gr.Group():
|
| 100 |
+
content = gr.Radio(content_choices, label="Content (incl. Structure)", value=content_choices[1])
|
| 101 |
+
with gr.Group():
|
| 102 |
+
voice = gr.Radio(voice_choices, label="Voice", value=voice_choices[1])
|
| 103 |
+
with gr.Group():
|
| 104 |
+
pronunciation = gr.Radio(pronunciation_choices, label="Pronunciation (Only for HBC)")
|
| 105 |
+
with gr.Column():
|
| 106 |
+
with gr.Group():
|
| 107 |
+
bodyLanguage = gr.Radio(body_language_choices, label="Body Language", value=body_language_choices[1])
|
| 108 |
+
with gr.Group():
|
| 109 |
+
facialEyeContact = gr.Radio(facial_eye_contact_choices, label="Facial Expression + Eye Contact", value=facial_eye_contact_choices[1])
|
| 110 |
+
with gr.Group():
|
| 111 |
+
fluency = gr.Radio(fluency_choices, label="Fluency", value=fluency_choices[1])
|
| 112 |
+
with gr.Group():
|
| 113 |
+
slideDesign = gr.Radio(slide_design_choices, label="Slide Design (Only for HBS)")
|
| 114 |
+
with gr.Row():
|
| 115 |
+
gen_btn = gr.Button("Generate comment")
|
| 116 |
+
output = gr.Textbox(label="Teacher’s Comment", lines=5)
|
| 117 |
+
gen_btn.click(
|
| 118 |
+
generate_comment,
|
| 119 |
+
[title, style, content, bodyLanguage, facialEyeContact, voice, pronunciation, fluency, slideDesign],
|
| 120 |
+
output,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
demo.launch(server_name="0.0.0.0")
|