Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def send_request(input_dict):
|
| 6 |
+
|
| 7 |
+
headers = {
|
| 8 |
+
'accept': 'application/json',
|
| 9 |
+
'access-key': os.getenv('access_key'),
|
| 10 |
+
'Content-Type': 'application/json',
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
json_data = input_dict
|
| 14 |
+
print(json_data)
|
| 15 |
+
|
| 16 |
+
response = requests.post(
|
| 17 |
+
'https://dev-tutor-chatbot.vuihoc.vn/api/generate_evaluation',
|
| 18 |
+
headers=headers,
|
| 19 |
+
json=json_data,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
return response.json()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def gen(*args):
|
| 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 = send_request(input_dict)
|
| 40 |
+
return response["evaluation"]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
with gr.Row():
|
| 45 |
+
# --- Nhóm các thành phần nhập liệu ---
|
| 46 |
+
with gr.Column():
|
| 47 |
+
with gr.Group():
|
| 48 |
+
review = [
|
| 49 |
+
gr.Radio([1,2,3,4,5], label="Khả năng tiếp thu", show_label=True),
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
with gr.Group():
|
| 53 |
+
review += [
|
| 54 |
+
gr.Radio([1,2,3,4,5], label="Ghi nhớ từ vựng mới", show_label=True),
|
| 55 |
+
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"),
|
| 56 |
+
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"),
|
| 57 |
+
]
|
| 58 |
+
with gr.Group():
|
| 59 |
+
review += [
|
| 60 |
+
gr.Radio([1,2,3,4,5], label="Phát âm", show_label=True),
|
| 61 |
+
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"),
|
| 62 |
+
]
|
| 63 |
+
with gr.Column():
|
| 64 |
+
with gr.Group():
|
| 65 |
+
review += [
|
| 66 |
+
gr.Radio([1,2,3,4,5], label="Ghi nhớ cấu trúc mới", show_label=True),
|
| 67 |
+
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"),
|
| 68 |
+
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"),
|
| 69 |
+
]
|
| 70 |
+
with gr.Group():
|
| 71 |
+
review += [
|
| 72 |
+
gr.Radio([1,2,3,4,5], label="Khả năng tương tác", show_label=True),
|
| 73 |
+
]
|
| 74 |
+
with gr.Group():
|
| 75 |
+
review += [
|
| 76 |
+
gr.Radio([
|
| 77 |
+
"Học sinh thiếu tập trung, hay làm việc riêng trong lớp",
|
| 78 |
+
"Mạng của học sinh kém ảnh hưởng tới chất lượng buổi học",
|
| 79 |
+
"Học sinh thiếu lễ phép với thầy cô"
|
| 80 |
+
], 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),
|
| 81 |
+
]
|
| 82 |
+
with gr.Column():
|
| 83 |
+
# debug_output = gr.Textbox(label="Thông tin đánh giá", show_copy_button=True)
|
| 84 |
+
evaluation = gr.Textbox(label="Nhận xét", show_copy_button=True)
|
| 85 |
+
|
| 86 |
+
greet_btn = gr.Button("Tạo nhận xét")
|
| 87 |
+
|
| 88 |
+
greet_btn.click(gen, inputs=[*review], outputs=[evaluation])
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
demo.launch(auth=(os.getenv('username'), os.getenv('password')))
|