Spaces:
Running
Running
tiennguyenbnbk
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
-
def
|
6 |
|
7 |
headers = {
|
8 |
'accept': 'application/json',
|
@@ -14,78 +14,152 @@ def send_request(input_dict):
|
|
14 |
print(json_data)
|
15 |
|
16 |
response = requests.post(
|
17 |
-
'https://dev-tutor-chatbot.vuihoc.vn/api/
|
18 |
headers=headers,
|
19 |
json=json_data,
|
20 |
)
|
21 |
|
22 |
return response.json()
|
23 |
|
|
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
input_dict = {
|
27 |
-
'reception': args[0],
|
28 |
-
'remember_new_vocabulary': args[1],
|
29 |
-
'vocabulary_student_remember': args[2],
|
30 |
-
'vocabulary_student_not_remember': args[3],
|
31 |
-
'remember_new_grammar': args[6],
|
32 |
-
'grammar_student_remember': args[7],
|
33 |
-
'grammar_student_not_remember': args[8],
|
34 |
-
'pronounce': args[4],
|
35 |
-
'pronounce_error': args[5],
|
36 |
-
'interaction': args[9],
|
37 |
-
'note': args[10],
|
38 |
}
|
39 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
return response["evaluation"].replace("**", '"')
|
41 |
|
42 |
|
43 |
with gr.Blocks() as demo:
|
44 |
-
with gr.
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
gr.
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
gr.
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
gr.
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
gr.
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
gr.
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
demo.launch(auth=(os.getenv('username'), os.getenv('password')))
|
|
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
+
def send_request_english(input_dict):
|
6 |
|
7 |
headers = {
|
8 |
'accept': 'application/json',
|
|
|
14 |
print(json_data)
|
15 |
|
16 |
response = requests.post(
|
17 |
+
'https://dev-tutor-chatbot.vuihoc.vn/api/generate_evaluation_english',
|
18 |
headers=headers,
|
19 |
json=json_data,
|
20 |
)
|
21 |
|
22 |
return response.json()
|
23 |
|
24 |
+
def send_request_math(input_dict):
|
25 |
|
26 |
+
headers = {
|
27 |
+
'accept': 'application/json',
|
28 |
+
'access-key': os.getenv('access_key'),
|
29 |
+
'Content-Type': 'application/json',
|
30 |
+
}
|
31 |
+
|
32 |
+
json_data = input_dict
|
33 |
+
print(json_data)
|
34 |
+
|
35 |
+
response = requests.post(
|
36 |
+
'https://dev-tutor-chatbot.vuihoc.vn/api/generate_evaluation_math',
|
37 |
+
headers=headers,
|
38 |
+
json=json_data,
|
39 |
+
)
|
40 |
+
|
41 |
+
return response.json()
|
42 |
+
|
43 |
+
|
44 |
+
def gen_english(*args):
|
45 |
input_dict = {
|
46 |
+
'reception': args[0] if args[0] else None,
|
47 |
+
'remember_new_vocabulary': args[1] if args[1] else None,
|
48 |
+
'vocabulary_student_remember': args[2] if args[2] else "",
|
49 |
+
'vocabulary_student_not_remember': args[3] if args[3] else "",
|
50 |
+
'remember_new_grammar': args[6] if args[6] else None,
|
51 |
+
'grammar_student_remember': args[7] if args[7] else "",
|
52 |
+
'grammar_student_not_remember': args[8] if args[8] else "",
|
53 |
+
'pronounce': args[4] if args[4] else None,
|
54 |
+
'pronounce_error': args[5] if args[5] else "",
|
55 |
+
'interaction': args[9] if args[9] else None,
|
56 |
+
'note': args[10] if args[10] else "",
|
57 |
}
|
58 |
+
response = send_request_english(input_dict)
|
59 |
+
return response["evaluation"].replace("**", '"')
|
60 |
+
|
61 |
+
def gen_math(*args):
|
62 |
+
input_dict = {
|
63 |
+
'reception': args[0] if args[0] else None,
|
64 |
+
'exercise_format_understanding': args[1] if args[1] else "",
|
65 |
+
'exercise_format_not_understanding': args[2] if args[2] else "",
|
66 |
+
'problem_solving_and_presentation': args[3] if args[3] else None,
|
67 |
+
'interaction': args[4] if args[4] else None,
|
68 |
+
'note': args[5] if args[5] else "",
|
69 |
+
}
|
70 |
+
response = send_request_math(input_dict)
|
71 |
return response["evaluation"].replace("**", '"')
|
72 |
|
73 |
|
74 |
with gr.Blocks() as demo:
|
75 |
+
with gr.Tabs():
|
76 |
+
with gr.Tab("Môn Tiếng Anh"):
|
77 |
+
with gr.Row():
|
78 |
+
# --- Nhóm các thành phần nhập liệu ---
|
79 |
+
with gr.Column():
|
80 |
+
with gr.Group():
|
81 |
+
review = [
|
82 |
+
gr.Radio([1,2,3,4,5], value=3, label="Khả năng tiếp thu", show_label=True),
|
83 |
+
]
|
84 |
+
|
85 |
+
with gr.Group():
|
86 |
+
review += [
|
87 |
+
gr.Radio([1,2,3,4,5], value=3, label="Ghi nhớ từ vựng mới", show_label=True),
|
88 |
+
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"),
|
89 |
+
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"),
|
90 |
+
]
|
91 |
+
with gr.Group():
|
92 |
+
review += [
|
93 |
+
gr.Radio([1,2,3,4,5], value=3, label="Phát âm", show_label=True),
|
94 |
+
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"),
|
95 |
+
]
|
96 |
+
with gr.Column():
|
97 |
+
with gr.Group():
|
98 |
+
review += [
|
99 |
+
gr.Radio([1,2,3,4,5], value=3, label="Ghi nhớ cấu trúc mới", show_label=True),
|
100 |
+
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"),
|
101 |
+
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"),
|
102 |
+
]
|
103 |
+
with gr.Group():
|
104 |
+
review += [
|
105 |
+
gr.Radio([1,2,3,4,5], value=3, label="Khả năng tương tác", show_label=True),
|
106 |
+
]
|
107 |
+
with gr.Group():
|
108 |
+
review += [
|
109 |
+
gr.Radio([
|
110 |
+
"Học sinh thiếu tập trung, hay làm việc riêng trong lớp",
|
111 |
+
"Mạng của học sinh kém ảnh hưởng tới chất lượng buổi học",
|
112 |
+
"Học sinh thiếu lễ phép với thầy cô"
|
113 |
+
], 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),
|
114 |
+
]
|
115 |
+
with gr.Column():
|
116 |
+
# debug_output = gr.Textbox(label="Thông tin đánh giá", show_copy_button=True)
|
117 |
+
evaluation = gr.Textbox(label="Nhận xét", show_copy_button=True)
|
118 |
+
|
119 |
+
greet_btn = gr.Button("Tạo nhận xét")
|
120 |
+
|
121 |
+
greet_btn.click(gen_english, inputs=[*review], outputs=[evaluation])
|
122 |
+
|
123 |
+
with gr.Tab("Môn Toán"):
|
124 |
+
with gr.Row():
|
125 |
+
# --- Nhóm các thành phần nhập liệu ---
|
126 |
+
with gr.Column():
|
127 |
+
with gr.Group():
|
128 |
+
review = [
|
129 |
+
gr.Radio([1,2,3,4,5], value=3, label="Khả năng tiếp thu", show_label=True),
|
130 |
+
]
|
131 |
+
with gr.Group():
|
132 |
+
review += [
|
133 |
+
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"),
|
134 |
+
]
|
135 |
+
with gr.Group():
|
136 |
+
review += [
|
137 |
+
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"),
|
138 |
+
]
|
139 |
+
with gr.Column():
|
140 |
+
with gr.Group():
|
141 |
+
review += [
|
142 |
+
gr.Radio([1,2,3,4,5], value=3, label="Giải quyết vấn đề & trình bày", show_label=True),
|
143 |
+
]
|
144 |
+
with gr.Group():
|
145 |
+
review += [
|
146 |
+
gr.Radio([1,2,3,4,5], value=3, label="Khả năng tương tác", show_label=True),
|
147 |
+
]
|
148 |
+
with gr.Group():
|
149 |
+
review += [
|
150 |
+
gr.Radio([
|
151 |
+
"Học sinh thiếu tập trung, hay làm việc riêng trong lớp",
|
152 |
+
"Mạng của học sinh kém ảnh hưởng tới chất lượng buổi học",
|
153 |
+
"Học sinh thiếu lễ phép với thầy cô"
|
154 |
+
], 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),
|
155 |
+
]
|
156 |
+
with gr.Column():
|
157 |
+
# debug_output = gr.Textbox(label="Thông tin đánh giá", show_copy_button=True)
|
158 |
+
evaluation = gr.Textbox(label="Nhận xét", show_copy_button=True)
|
159 |
+
|
160 |
+
greet_btn = gr.Button("Tạo nhận xét")
|
161 |
+
|
162 |
+
greet_btn.click(gen_math, inputs=[*review], outputs=[evaluation])
|
163 |
|
164 |
if __name__ == "__main__":
|
165 |
demo.launch(auth=(os.getenv('username'), os.getenv('password')))
|