Spaces:
Running
Running
| 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() | |
| mapping_score_en = { | |
| "1 - Poor" : 1, | |
| "2 - Average" : 2, | |
| "3 - Good" : 3, | |
| "4 - Very Good" : 4, | |
| "5 - Excellent" : 5, | |
| } | |
| mapping_score_vi = { | |
| "1 - Yếu" : 1, | |
| "2 - Trung bình" : 2, | |
| "3 - Khá" : 3, | |
| "4 - Tốt" : 4, | |
| "5 - Tuyệt vời" : 5, | |
| } | |
| mapping_note_en = { | |
| "Complete Workbook exercises before class (Do not check if there is no Workbook exercises)": "Cần hoàn thành bài tập trong Workbook", | |
| "Pay more attention and don't do your own work in class": "Cần tập trung hơn và không làm việc riêng trong lớp", | |
| "Do not turn off the camera frequently": "Không tắt camera trong buổi học", | |
| "Need to fix internet quality": "Kiểm tra lại chất lượng mạng internet", | |
| "Need to fix camera/mic error": "Sửa lỗi cam, lỗi mic", | |
| "Avoid studying in noisy and crowded places": "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại", | |
| "Be polite to teachers": "Lễ phép với thầy cô", | |
| } | |
| mapping_note_vi = { | |
| "Hoàn thành bài tập Workbook (Không tích nếu không có bài tập Workbook)": "Cần hoàn thành bài tập trong Workbook", | |
| "Cần tập trung hơn và không làm việc riêng trong lớp": "Cần tập trung hơn và không làm việc riêng trong lớp", | |
| "Không tắt cam trong buổi học": "Không tắt camera trong buổi học", | |
| "Kiểm tra lại chất lượng mạng internet": "Kiểm tra lại chất lượng mạng internet", | |
| "Sửa lỗi cam, lỗi mic": "Sửa lỗi cam, lỗi mic", | |
| "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại": "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại", | |
| "Lễ phép với thầy cô": "Lễ phép với thầy cô", | |
| } | |
| def gen_english(*args): | |
| input_dict = { | |
| 'title': "Cô" if args[0] == "Female teacher" else "Thầy" if args[0] else None, | |
| 'reception': mapping_score_en.get(args[1]) if args[1] else None, | |
| 'participate_activities': mapping_score_en.get(args[2]) if args[2] else None, | |
| 'remember_apply_vocab_grama': mapping_score_en.get(args[3]) if args[3] else None, | |
| 'note': [mapping_note_en.get(x) for x in args[4]] if args[4] else "", | |
| 'pronounce': mapping_score_en.get(args[5]) if args[5] else None, | |
| 'remember_apply_strategies': mapping_score_en.get(args[6]) if args[6] else None, | |
| 'vocabulary_need_improve': args[7] if args[7] else "", | |
| 'grammar_need_improve': args[8] if args[8] else "", | |
| 'exercise_need_improve': args[9] if args[9] else "", | |
| 'note_for_skills': args[10] if args[10] else "", | |
| } | |
| response = send_request_english(input_dict) | |
| return response["evaluation"].replace("**", '"') | |
| def gen_math(*args): | |
| input_dict = { | |
| 'title': "Cô" if args[0] == "Cô giáo" else "Thầy" if args[0] else None, | |
| 'reception': mapping_score_vi.get(args[1]) if args[1] else None, | |
| 'exercise_format_understanding': args[2] if args[2] else "", | |
| 'exercise_format_not_understanding': args[3] if args[3] else "", | |
| 'more_evaluations': args[4] if args[4] else "", | |
| 'participate_activities': mapping_score_vi.get(args[5]) if args[5] else None, | |
| 'problem_solving_and_presentation': mapping_score_vi.get(args[6]) if args[6] else None, | |
| 'note': [mapping_note_vi.get(x) for x in args[7]] if args[7] else "", | |
| } | |
| print(input_dict) | |
| 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(["Female teacher", "Male teacher"], value="Female teacher", label="I am a", show_label=True), | |
| ] | |
| with gr.Group(): | |
| review += [ | |
| gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Learning ability", show_label=True), | |
| gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Participation in class activities", show_label=True), | |
| gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Ability to remember and apply learned vocabulary/ grammar structures", show_label=True), | |
| ] | |
| with gr.Group(): | |
| review += [ | |
| gr.CheckboxGroup([ | |
| "Complete Workbook exercises before class (Do not check if there is no Workbook exercises)", | |
| "Pay more attention and don't do your own work in class", | |
| "Do not turn off the camera frequently", | |
| "Need to fix internet quality", | |
| "Need to fix camera/mic error", | |
| "Avoid studying in noisy and crowded places", | |
| "Be polite to teachers", | |
| ], label="Things to improve for better learning outcomes", show_label=True), | |
| ] | |
| with gr.Column(): | |
| with gr.Group(): | |
| review += [ | |
| gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Pronunciation when using English to communicate", show_label=True), | |
| ] | |
| with gr.Group(): | |
| review += [ | |
| gr.Radio(["1 - Poor","2 - Average","3 - Good","4 - Very Good","5 - Excellent"], value="3 - Good", label="Ability to remember and apply strategies to different types of questions (optional)", show_label=True), | |
| ] | |
| with gr.Group(): | |
| review += [ | |
| gr.Textbox(lines=1, label="Words that need further practice", placeholder="Separate words by semicolons ;"), | |
| gr.Textbox(lines=1, label="Structures/Grammar point that need further practice", placeholder="Separate structures by semicolons ;"), | |
| gr.Textbox(lines=1, label="Type of exercises that need further practice (optional)", placeholder="Exercises..."), | |
| gr.Textbox(lines=3, label="Other notes on listening, speaking, reading and writing skills (optional)", placeholder="Note..."), | |
| ] | |
| with gr.Column(): | |
| # debug_output = gr.Textbox(label="Thông tin đánh giá", show_copy_button=True) | |
| evaluation = gr.Textbox(label="Evaluation", show_copy_button=True) | |
| greet_btn = gr.Button("Generate evaluation") | |
| 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(["Cô giáo", "Thầy giáo"], value="Cô giáo", label="Bạn là", show_label=True), | |
| ] | |
| with gr.Group(): | |
| review += [ | |
| gr.Radio(["1 - Yếu","2 - Trung bình","3 - Khá","4 - Tốt","5 - Tuyệt vời"], value="3 - Khá", 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="Dạng bài..."), | |
| gr.Textbox(lines=1, label="Con cần luyện tập thêm về dạng bài", placeholder="Dạng bài..."), | |
| gr.Textbox(lines=1, label="Nhận xét thêm (nếu có)", placeholder="Nhận xét..."), | |
| ] | |
| with gr.Column(): | |
| with gr.Group(): | |
| review += [ | |
| gr.Radio(["1 - Yếu","2 - Trung bình","3 - Khá","4 - Tốt","5 - Tuyệt vời"], value="3 - Khá", label="Tham gia vào các hoạt động trong lớp", show_label=True), | |
| ] | |
| with gr.Group(): | |
| review += [ | |
| gr.Radio(["1 - Yếu","2 - Trung bình","3 - Khá","4 - Tốt","5 - Tuyệt vời"], value="3 - Khá", label="Giải quyết vấn đề & trình bày", show_label=True), | |
| ] | |
| with gr.Group(): | |
| review += [ | |
| gr.CheckboxGroup([ | |
| "Hoàn thành bài tập Workbook (Không tích nếu không có bài tập Workbook)", | |
| "Cần tập trung hơn và không làm việc riêng trong lớp", | |
| "Không tắt cam trong buổi học", | |
| "Kiểm tra lại chất lượng mạng internet", | |
| "Sửa lỗi cam, lỗi mic", | |
| "Tránh ngồi học nơi có nhiều tiếng ồn, nhiều người qua lại", | |
| "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() | |