gen_evaluation / app.py
tiennguyenbnbk's picture
Update app.py
4981844 verified
raw
history blame
7.75 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 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')))