| import gradio as gr |
| from huggingface_hub import InferenceClient |
| import pandas as pd |
|
|
| df = pd.read_csv("Diemthi2024_processed.csv") |
|
|
| def respond( |
| sbd, khoi |
| ): |
| score = df[df['sbd'] == int(sbd)] |
| count_all = (df[khoi] >= score[khoi].iloc[0]).sum() |
| count_kv = ((df[khoi] >= score[khoi].iloc[0]) & (df['kv'] == score['kv'].iloc[0])).sum() |
| count_tinh = ((df[khoi] >= score[khoi].iloc[0]) & (df['tinh'] == score['tinh'].iloc[0])).sum() |
|
|
| count_all_noscore = (df[khoi] >= 0).sum() |
| count_kv_noscore = ((df[khoi] >= 0) & (df['kv'] == score['kv'].iloc[0])).sum() |
| count_tinh_noscore = ((df[khoi] >= 0) & (df['tinh'] == score['tinh'].iloc[0])).sum() |
|
|
| return f"""Tổng điểm theo khối {khoi} của bạn là: {score[khoi].iloc[0]} |
| Thứ hạng toàn quốc: {count_all} / {count_all_noscore} |
| Thứ hạng theo khu vực: {count_kv} / {count_kv_noscore} |
| Thứ hạng theo tỉnh: {count_tinh} / {count_tinh_noscore}""", score.iloc[:, 1:10] |
|
|
| """ |
| Chatbot |
| """ |
| with gr.Blocks() as demo: |
| gr.Markdown( |
| """ |
| <style> |
| .gr-button-secondary { |
| width: 100px; |
| height: 30px; |
| padding: 5px; |
| } |
| .gr-row { |
| display: flex; |
| align-items: center; |
| gap: 10px; |
| } |
| .gr-block { |
| padding: 20px; |
| } |
| .gr-markdown p { |
| font-size: 16px; |
| } |
| </style> |
| <span style='font-family: Arial, sans-serif; font-size: 20px;'>Xếp hạng điểm thi Tốt nghiệp THPT 2024</span> |
| <p style='font-family: Arial, sans-serif;'>Nhập số báo danh và lựa chọn tổ hợp của bạn bên dưới</p> |
| """ |
| ) |
| with gr.Row(): |
| id = gr.Textbox(placeholder="Nhập SBD của bạn", label="Nhập SBD của bạn:", lines=1) |
| comb = gr.Dropdown( |
| ["A00","A01","A02","A03","A04","A05","A06","A07","A08","A09","A10","A11","A12","A14","A15","A16","A17","A18","B00","B01","B02","B03","B04","B05","B08","C00","C01","C02","C03","C04","C05","C06","C07","C08","C09","C10","C12","C13","C14","C15","C16","C17","C18","C19","C20","D01","D07","D08","D09","D10","D11","D12","D13","D14","D15","D66","D72","D78","D84","D90","D96"], label="Chọn tổ hợp của bạn:", info="Đang cập nhật thêm các tổ hợp..." |
| ) |
| |
| with gr.Row(): |
| check_button = gr.Button("Tra cứu!", variant="primary") |
|
|
| dfShow = gr.DataFrame(label="Điểm thi", col_count=(9, "fixed"), row_count=(1, "fixed")) |
| out = gr.Textbox(label="Xếp hạng", placeholder="", lines=2) |
| |
| check_button.click(fn=respond, inputs=[id,comb], outputs=[out,dfShow]) |
|
|
| gr.Markdown( |
| """ |
| <p style='font-family: Arial, sans-serif;'>Bản quyền dữ liệu thuộc về Bộ Giáo dục và Đào tạo. ©️ <a href="https://ngocminhta.id.vn/">Ngoc-Minh Ta</a> 2024.</p> |
| """ |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |