File size: 7,748 Bytes
22fc150
 
 
 
4981844
22fc150
 
 
 
 
 
 
 
 
 
 
4981844
22fc150
 
 
 
 
 
4981844
22fc150
4981844
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22fc150
4981844
 
 
 
 
 
 
 
 
 
 
22fc150
4981844
 
 
 
 
 
 
 
 
 
 
 
 
d514ccc
22fc150
 
 
4981844
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22fc150
 
 
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
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/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/generate_evaluation_math',
        headers=headers,
        json=json_data,
    )

    return response.json()


def gen_english(*args):
    input_dict = {
    'reception': args[0] if args[0] else None,
    'remember_new_vocabulary': args[1] if args[1] else None,
    'vocabulary_student_remember': args[2] if args[2] else "",
    'vocabulary_student_not_remember': args[3] if args[3] else "",
    'remember_new_grammar': args[6] if args[6] else None,
    'grammar_student_remember': args[7] if args[7] else "",
    'grammar_student_not_remember': args[8] if args[8] else "",
    'pronounce': args[4] if args[4] else None,
    'pronounce_error': args[5] if args[5] else "",
    'interaction': args[9] if args[9] else None,
    'note': args[10] if args[10] else "",
}
    response = send_request_english(input_dict)
    return response["evaluation"].replace("**", '"')

def gen_math(*args):
    input_dict = {
    'reception': args[0] if args[0] else None,
    'exercise_format_understanding': args[1] if args[1] else "",
    'exercise_format_not_understanding': args[2] if args[2] else "",
    'problem_solving_and_presentation': args[3] if args[3] else None,
    'interaction': args[4] if args[4] else None,
    'note': args[5] if args[5] else "",
}
    response = send_request_math(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.Group():
                        review = [
                            gr.Radio([1,2,3,4,5], value=3, label="Khả năng tiếp thu", show_label=True),
                            ]
                    
                    with gr.Group():
                        review += [
                            gr.Radio([1,2,3,4,5], value=3, label="Ghi nhớ từ vựng mới", show_label=True),
                            gr.Textbox(lines=1, label="Các từ vựng con ghi nhớ và vận dụng", placeholder="Điền các từ vựng cách nhau bởi dấu chấm phẩy"),
                            gr.Textbox(lines=1, label="Các từ vựng con chưa ghi nhớ", placeholder="Điền các từ vựng cách nhau bởi dấu chấm phẩy"),
                            ]
                    with gr.Group():
                        review += [
                            gr.Radio([1,2,3,4,5], value=3, label="Phát âm", show_label=True),
                            gr.Textbox(lines=1, label="Lỗi phát âm con hay mắc khi nói", placeholder="Điền các lỗi phát âm cách nhau bởi dấu chấm phẩy"),
                            ]
                with gr.Column():
                    with gr.Group():
                        review += [
                            gr.Radio([1,2,3,4,5], value=3, label="Ghi nhớ cấu trúc mới", show_label=True),
                            gr.Textbox(lines=1, label="Các cấu trúc con ghi nhớ và vận dụng", placeholder="Điền các cấu trúc cách nhau bởi dấu chấm phẩy"),
                            gr.Textbox(lines=1, label="Các cấu trúc con chưa ghi nhớ", placeholder="Điền các cấu trúc cách nhau bởi dấu chấm phẩy"),
                            ]
                    with gr.Group():
                        review += [
                            gr.Radio([1,2,3,4,5], value=3, label="Khả năng tương tác", show_label=True),
                            ]
                    with gr.Group():
                        review += [
                                gr.Radio([
                                "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ô"
                                ], 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_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.Group():
                        review = [
                            gr.Radio([1,2,3,4,5], value=3, 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="Điền thông tin"),
                            ]
                    with gr.Group():
                        review += [
                            gr.Textbox(lines=1, label="Con cần luyện tập thêm về dạng bài", placeholder="Điền thông tin"),
                            ]                    
                with gr.Column():                     
                    with gr.Group():
                        review += [
                            gr.Radio([1,2,3,4,5], value=3, label="Giải quyết vấn đề & trình bày", show_label=True),
                            ]
                    with gr.Group():
                        review += [
                            gr.Radio([1,2,3,4,5], value=3, label="Khả năng tương tác", show_label=True),
                            ]
                    with gr.Group():
                        review += [
                                gr.Radio([
                                "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ô"
                                ], 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_math, inputs=[*review], outputs=[evaluation])

if __name__ == "__main__":
    demo.launch(auth=(os.getenv('username'), os.getenv('password')))