Spaces:
Running
Running
import gradio as gr | |
import requests | |
import os | |
def send_request(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', | |
headers=headers, | |
json=json_data, | |
) | |
return response.json() | |
def gen(*args): | |
input_dict = { | |
'reception': args[0], | |
'remember_new_vocabulary': args[1], | |
'vocabulary_student_remember': args[2], | |
'vocabulary_student_not_remember': args[3], | |
'remember_new_grammar': args[6], | |
'grammar_student_remember': args[7], | |
'grammar_student_not_remember': args[8], | |
'pronounce': args[4], | |
'pronounce_error': args[5], | |
'interaction': args[9], | |
'note': args[10], | |
} | |
response = send_request(input_dict) | |
return response["evaluation"] | |
with gr.Blocks() as demo: | |
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], label="Khả năng tiếp thu", show_label=True), | |
] | |
with gr.Group(): | |
review += [ | |
gr.Radio([1,2,3,4,5], 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", info="Đ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ớ", info="Đ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], label="Phát âm", show_label=True), | |
gr.Textbox(lines=1, label="Lỗi phát âm con hay mắc khi nói", info="Đ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], 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", info="Đ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ớ", info="Đ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], 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, inputs=[*review], outputs=[evaluation]) | |
if __name__ == "__main__": | |
demo.launch(auth=(os.getenv('username'), os.getenv('password'))) | |