File size: 18,656 Bytes
22fc150
 
 
 
4981844
22fc150
 
 
 
 
 
 
 
 
 
 
6cbfed5
22fc150
 
 
 
 
 
4981844
22fc150
4981844
 
 
 
 
 
 
 
 
 
6cbfed5
4981844
 
 
 
 
 
9d85e64
 
 
 
 
 
 
 
 
 
 
 
6cbfed5
9d85e64
 
 
 
 
 
4981844
2676c78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268facb
2676c78
268facb
2676c78
 
 
 
268facb
2676c78
 
 
 
 
268facb
2676c78
268facb
2676c78
 
 
 
268facb
2676c78
 
 
560c473
 
 
 
 
 
4981844
c5a716e
22fc150
2676c78
c5a716e
560c473
 
 
 
 
 
 
 
 
 
22fc150
4981844
 
 
 
c5a716e
4981844
2676c78
c5a716e
560c473
 
 
 
 
 
 
2676c78
268facb
4981844
d514ccc
9d85e64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22fc150
 
 
4981844
 
 
 
 
560c473
 
 
 
 
 
 
c5a716e
560c473
4981844
 
2676c78
 
 
4981844
2676c78
4981844
 
2676c78
 
268facb
2676c78
268facb
2676c78
 
 
 
268facb
2676c78
268facb
4981844
 
 
 
2676c78
 
4981844
 
2676c78
4981844
 
 
2676c78
 
 
 
4981844
 
 
2676c78
4981844
2676c78
4981844
 
 
 
 
 
 
560c473
 
 
 
 
 
 
c5a716e
560c473
4981844
 
2676c78
4981844
 
 
2676c78
 
 
4981844
 
 
 
2676c78
4981844
 
 
2676c78
4981844
 
 
2676c78
 
268facb
2676c78
268facb
2676c78
 
 
 
268facb
2676c78
268facb
4981844
 
 
 
 
 
 
 
2676c78
c5a716e
2676c78
 
 
 
 
 
 
 
9d85e64
2676c78
 
 
 
 
 
 
 
 
 
 
9d85e64
2676c78
 
 
 
 
 
 
 
9d85e64
2676c78
 
 
 
 
9d85e64
 
2676c78
 
 
 
 
 
 
 
 
9d85e64
2676c78
 
 
9d85e64
2676c78
22fc150
2676c78
9d85e64
22fc150
f7f9b04
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import gradio as gr
import requests
import os

def send_request_english(input_dict):

    headers = {
        'accept': 'application/json',
        'access-key': os.getenv('access_key'),
        'Content-Type': 'application/json',
    }

    json_data = input_dict
    print(json_data)

    response = requests.post(
        'https://dev-tutor-chatbot.vuihoc.vn/api/v1/generate_evaluation_english',
        headers=headers,
        json=json_data,
    )

    return response.json()

def send_request_math(input_dict):

    headers = {
        'accept': 'application/json',
        'access-key': os.getenv('access_key'),
        'Content-Type': 'application/json',
    }

    json_data = input_dict
    print(json_data)

    response = requests.post(
        'https://dev-tutor-chatbot.vuihoc.vn/api/v1/generate_evaluation_math',
        headers=headers,
        json=json_data,
    )

    return response.json()

def send_request_ielts(input_dict):

    headers = {
        'accept': 'application/json',
        'access-key': os.getenv('access_key'),
        'Content-Type': 'application/json',
    }

    json_data = input_dict
    print(json_data)

    response = requests.post(
        'https://dev-tutor-chatbot.vuihoc.vn/api/v1/generate_evaluation_ielts',
        headers=headers,
        json=json_data,
    )

    return response.json()


mapping_score_en = {
    "1 - Poor" : 1,
    "2 - Average" : 2,
    "3 - Good" : 3,
    "4 - Very Good" : 4,
    "5 - Excellent" : 5,
    }
mapping_score_vi = {
    "1 - Yếu" : 1,
    "2 - Trung bình" : 2,
    "3 - Khá" : 3,
    "4 - Tốt" : 4,
    "5 - Tuyệt vời" : 5,
    }

mapping_note_en = {
    "Complete Workbook exercises before class (Do not check if there is no Workbook exercises)": "Cần hoàn thành bài tập trong Workbook",
    "Prepare all necessary learning materials (Classbook, Workbook, and other supplies)": "Cần chuẩn bị đồ dùng học tập cần thiết",
    "Pay more attention and don't do your own work in class": "Cần tập trung hơn và không làm việc riêng trong lớp",
    "Be confident in interacting with the teacher and classmates in class": "Tự tin tương tác với thầy cô và các bạn trong lớp",
    "Do not turn off the camera frequently": "Không tắt camera trong buổi học",
    "Need to fix internet quality": "Kiểm tra lại chất lượng mạng internet",
    "Need to fix camera/mic error": "Sửa lỗi cam, lỗi mic",
    "Avoid studying in noisy and crowded places": "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại",
    "Follow the class rules": "Tuân theo quy tắc của lớp học",
    "Be polite to teachers": "Lễ phép với thầy cô",
    }

mapping_note_vi = {
    "Hoàn thành bài tập Workbook (Không tích nếu không có bài tập Workbook)": "Cần hoàn thành bài tập trong Workbook",
    "Chuẩn bị đồ dùng học tập cần thiết (Classbook, Workbook, và các đồ dùng khác)": "Cần chuẩn bị đồ dùng học tập cần thiết",
    "Cần tập trung hơn và không làm việc riêng trong lớp": "Cần tập trung hơn và không làm việc riêng trong lớp",
    "Tự tin tương tác với thầy cô và các bạn trong lớp": "Tự tin tương tác với thầy cô và các bạn trong lớp",
    "Không tắt cam trong buổi học": "Không tắt camera trong buổi học",
    "Kiểm tra lại chất lượng mạng internet": "Kiểm tra lại chất lượng mạng internet",
    "Sửa lỗi cam, lỗi mic": "Sửa lỗi cam, lỗi mic",
    "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại": "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại",
    "Tuân theo quy tắc của lớp học": "Tuân theo quy tắc của lớp học",
    "Lễ phép với thầy cô": "Lễ phép với thầy cô",
    }

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 gen_english(*args):
    style = [mapping_style_en.get(x).lower() for x in args[1]]
    input_dict = {
        'title': "Cô" if args[0] == "Female teacher" else "Thầy" if args[0] else None,
        'style':  ", ".join(style) if len(args[1])!= 0 else None,
    'reception': mapping_score_en.get(args[2]) if args[2] else None,
    'participate_activities': mapping_score_en.get(args[3]) if args[3] else None,
    'remember_apply_vocab_grama': mapping_score_en.get(args[4]) if args[4] else None,
    'note': [mapping_note_en.get(x) for x in args[5]] if len(args[5])!= 0 else [],
    'pronounce': mapping_score_en.get(args[6]) if args[6] else None,
    'remember_apply_strategies': mapping_score_en.get(args[7]) if args[7] else None,
    'vocabulary_need_improve': args[8] if args[8] else "",
    'grammar_need_improve': args[9] if args[9] else "",
    'exercise_need_improve': args[10] if args[10] else "",
    'note_for_skills': args[11] if args[11] else "",
}
    response = send_request_english(input_dict)
    return response["evaluation"].replace("**", '"')

def gen_math(*args):
    style = [x.lower() for x in args[1]] 
    input_dict = {
        'title': "Cô" if args[0] == "Cô giáo" else "Thầy" if args[0] else None,
        'style': ", ".join(style) if len(args[1])!= 0 else None,
    'reception': mapping_score_vi.get(args[2]) if args[2] else None,
    'exercise_format_understanding': args[3] if args[3] else "",
    'exercise_format_not_understanding': args[4] if args[4] else "",
    'more_evaluations': args[5] if args[5] else "",
    'participate_activities': mapping_score_vi.get(args[6]) if args[6] else None,
    'problem_solving_and_presentation': mapping_score_vi.get(args[7]) if args[7] else None,
    'note': [mapping_note_vi.get(x) for x in args[8]] if args[8] else [],
    }
    print(input_dict)
    response = send_request_math(input_dict)
    return response["evaluation"].replace("**", '"')

def gen_ielts(*args):
    input_dict = {
    'concentration': args[0] if args[0] else None,
    'participation': args[1] if args[1] else None,
    'exercise_need_improve': args[2] if args[2] else "",
    'grammar_need_improve': args[3] if args[3] else "",
    'structure_need_improve': args[4] if args[4] else "",
    'vocabulary_need_improve': args[5] if args[5] else "",
    'remember_apply_vocab_grammar': args[6] if args[6] else None,
    'remember_apply_strategies': args[7] if args[7] else None,
    'pronounce': args[8] if args[8] else None,
    'note': args[9] if args[9] else "",
    }
    response = send_request_ielts(input_dict)
    return response["evaluation"].replace("**", '"')
  

with gr.Blocks() as demo:
    with gr.Tabs():
        with gr.Tab("Môn Tiếng Anh"):
            with gr.Row():
                # --- Nhóm các thành phần nhập liệu ---
                with gr.Column():
                    with gr.Row():
                        with gr.Group():
                            review = [
                                gr.Radio(["Female teacher", "Male teacher"], value="Female teacher", label="I am a", show_label=True),
                                ]
                        with gr.Group():
                            review += [
                                gr.CheckboxGroup(["Close, friendly", "Short, concise", "Emotions"], value="Close, friendly", label="Evaluative Tone", show_label=True),
                                ]
                    with gr.Group():
                        review += [
                            gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Learning ability", show_label=True),
                            gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Participation in class activities", show_label=True),
                            gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Ability to remember and apply learned vocabulary/ grammar structures", show_label=True),
                            ]

                    with gr.Group():
                        review += [
                                gr.CheckboxGroup([
                                "Complete Workbook exercises before class (Do not check if there is no Workbook exercises)",
                                "Prepare all necessary learning materials (Classbook, Workbook, and other supplies)",
                                "Pay more attention and don't do your own work in class",
                                "Be confident in interacting with the teacher and classmates in class",
                                "Do not turn off the camera frequently",
                                "Need to fix internet quality",
                                "Need to fix camera/mic error",
                                "Avoid studying in noisy and crowded places",
                                "Follow the class rules",
                                "Be polite to teachers",
                                ], label="Things to improve for better learning outcomes (optional)", show_label=True),
                            ]
                with gr.Column():
                    with gr.Group():
                        review += [
                            gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Pronunciation when using English to communicate", show_label=True),
                            ]                    
                    with gr.Group():
                        review += [
                            gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Ability to remember and apply strategies to different types of questions (optional)", show_label=True),
                            ]
                    with gr.Group():
                        review += [
                            gr.Textbox(lines=1, label="Words that need further practice", placeholder="Separate words by semicolons ;"),
                            gr.Textbox(lines=1, label="Structures/Grammar point that need further practice", placeholder="Separate structures by semicolons ;"),
                            gr.Textbox(lines=1, label="Type of exercises that need further practice (optional)", placeholder="Exercises..."),
                            gr.Textbox(lines=3, label="Other notes on listening, speaking, reading and writing skills (optional)", placeholder="Note..."),
                            ]
            with gr.Column():
                # debug_output = gr.Textbox(label="Thông tin đánh giá", show_copy_button=True)
                evaluation = gr.Textbox(label="Evaluation", show_copy_button=True)

                greet_btn = gr.Button("Generate evaluation")

            greet_btn.click(gen_english, inputs=[*review], outputs=[evaluation])

        with gr.Tab("Môn Toán"):
            with gr.Row():
                # --- Nhóm các thành phần nhập liệu ---
                with gr.Column():
                    with gr.Row():
                        with gr.Group():
                            review = [
                                gr.Radio(["Cô giáo", "Thầy giáo"], value="Cô giáo", label="Bạn là", show_label=True),
                                ]
                        with gr.Group():
                            review += [
                                gr.CheckboxGroup(["Gần gũi, thân thiện", "Ngắn gọn, xúc tích", "Nhiều cảm xúc"], value="Gần gũi, thân thiện", label="Giọng văn đánh giá", show_label=True),
                                ]
                    with gr.Group():
                        review += [
                            gr.Radio(["1 - Yếu","2 - Trung bình","3 - Khá","4 - Tốt","5 - Tuyệt vời"], value="3 - Khá", label="Khả năng tiếp thu", show_label=True),
                            ]
                    with gr.Group():
                        review += [
                            gr.Textbox(lines=1, label="Con hiểu phương pháp và cách trình bày về dạng bài", placeholder="Dạng bài..."),
                            gr.Textbox(lines=1, label="Con cần luyện tập thêm về dạng bài", placeholder="Dạng bài..."),
                            gr.Textbox(lines=1, label="Nhận xét thêm (nếu có)", placeholder="Nhận xét..."),
                            ]                    
                with gr.Column():                     
                    with gr.Group():
                        review += [
                            gr.Radio(["1 - Yếu","2 - Trung bình","3 - Khá","4 - Tốt","5 - Tuyệt vời"], value="3 - Khá", label="Tham gia vào các hoạt động trong lớp", show_label=True),
                            ]
                    with gr.Group():
                        review += [
                            gr.Radio(["1 - Yếu","2 - Trung bình","3 - Khá","4 - Tốt","5 - Tuyệt vời"], value="3 - Khá", label="Giải quyết vấn đề & trình bày", show_label=True),
                            ]
                    with gr.Group():
                        review += [
                                gr.CheckboxGroup([
                                "Hoàn thành bài tập Workbook (Không tích nếu không có bài tập Workbook)",
                                "Chuẩn bị đồ dùng học tập cần thiết (Classbook, Workbook, và các đồ dùng khác)",
                                "Cần tập trung hơn và không làm việc riêng trong lớp",
                                "Tự tin tương tác với thầy cô và các bạn trong lớp",
                                "Không tắt cam trong buổi học",
                                "Kiểm tra lại chất lượng mạng internet",
                                "Sửa lỗi cam, lỗi mic",
                                "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại",
                                "Tuân theo quy tắc của lớp học",
                                "Lễ phép với thầy cô",
                                ], label="Những vấn đề cần cải thiện để buổi học đạt kết quả tốt hơn (nếu có)", show_label=True),
                            ]
            with gr.Column():
                # debug_output = gr.Textbox(label="Thông tin đánh giá", show_copy_button=True)
                evaluation = gr.Textbox(label="Nhận xét", show_copy_button=True)

                greet_btn = gr.Button("Tạo nhận xét")

            greet_btn.click(gen_math, inputs=[*review], outputs=[evaluation])
        
        
        # with gr.Tab("IELTS"):
        #     with gr.Row():
        #         # --- Nhóm các thành phần nhập liệu ---
        #         with gr.Column():
        #             with gr.Group():
        #                 review = [
        #                     gr.Radio([1,2,3,4,5], value=3, label="Mức độ tập trung của HV trong buổi học", show_label=True),
        #                     ]
                    
        #             with gr.Group():
        #                 review += [
        #                     gr.Radio([1,2,3,4,5], value=3, label="Mức độ tham gia của HV vào các hoạt động trong lớp", show_label=True),
        #                     ]
        #             with gr.Group():
        #                 review += [                            
        #                     gr.Textbox(lines=1, label="Dạng bài HV cần luyện tập thêm (nếu có)", placeholder="GV điền các điểm mà HV cần cải thiện"),
        #                     gr.Textbox(lines=1, label="Điểm ngữ pháp HV cần luyện tập thêm (nếu có)", placeholder="GV điền các điểm mà HV cần cải thiện"),
        #                     gr.Textbox(lines=1, label="Cấu trúc câu HV cần luyện tập thêm (nếu có)", placeholder="GV điền các điểm mà HV cần cải thiện"),
        #                     gr.Textbox(lines=1, label="Từ vựng  HV cần luyện tập thêm (nếu có)", placeholder="GV điền các điểm mà HV cần cải thiện"),
        #                     ]
                    
        #         with gr.Column():
        #             with gr.Group():
        #                 review += [
        #                     gr.Radio([1,2,3,4,5], value=3, label="Khả năng ghi nhớ và áp dụng các từ vựng/ cấu trúc ngữ pháp đã học", show_label=True),
        #                     ]
        #             with gr.Group():
        #                 review += [
        #                     gr.Radio([1,2,3,4,5], value=3, label="Khả năng ghi nhớ và áp dụng các chiến thuật cho các dạng bài khác nhau", show_label=True),

        #                     ]
        #             with gr.Group():
        #                 review += [
        #                     gr.Radio([1,2,3,4,5], value=3, label="Khả năng phát âm khi sử dụng tiếng Anh để trả lời các câu hỏi của GV", show_label=True),
        #                     ]

                        
        #             with gr.Group():
        #                 review += [
        #                         gr.CheckboxGroup([
        #                         "Học sinh thiếu tập trung, hay làm việc riêng trong lớp",
        #                         "Mạng của học sinh kém ảnh hưởng tới chất lượng buổi học",
        #                         "Học sinh thiếu lễ phép với thầy cô",
        #                         "Học sinh còn rụt rè, chưa tích cực phát biểu xây dựng bài"
        #                         ], label="Những vấn đề cần cải thiện để buổi học đạt kết quả tốt hơn", show_label=True),
        #                     ]
                    
        #     with gr.Column():
        #         # debug_output = gr.Textbox(label="Thông tin đánh giá", show_copy_button=True)
        #         evaluation = gr.Textbox(label="Nhận xét", show_copy_button=True)

        #         greet_btn = gr.Button("Tạo nhận xét")

        #     greet_btn.click(gen_ielts, inputs=[*review], outputs=[evaluation])
            
if __name__ == "__main__":
    # demo.launch(auth=(os.getenv('username'), os.getenv('password')))
    demo.launch()