File size: 4,114 Bytes
97cefd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e33167
97cefd7
 
 
 
 
 
 
 
 
8e33167
97cefd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d794c9
97cefd7
 
 
 
 
 
 
b0c6760
97cefd7
 
 
 
8e33167
97cefd7
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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",
}


# Gọi API và trả về comment
def generate_comment(
    title,
    style,
    content,
    bodyLanguage,
    facialEyeContact,
    voice,
    pronunciation,
    fluency
):
    payload = {
        "title": title,
        "style": mapping_style_en.get(style, style),  # Chuyển đổi style sang tiếng Việt
        "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}"


# Các lựa chọn chung cho radio buttons
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")