gen_evaluation / app.py
tiennguyenbnbk's picture
Update app.py
9d85e64 verified
raw
history blame
12.4 kB
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 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/generate_evaluation_ielts',
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("**", '"')
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.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])
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')))