ngocminhta/National-Grad-Score-Ranking-2
0
1import gradio as gr2from huggingface_hub import InferenceClient3import pandas as pd4 5df = pd.read_csv("Diemthi2024_processed.csv")6 7def respond(8 sbd, khoi9):10 score = df[df['sbd'] == int(sbd)]11 count_all = (df[khoi] >= score[khoi].iloc[0]).sum()12 count_kv = ((df[khoi] >= score[khoi].iloc[0]) & (df['kv'] == score['kv'].iloc[0])).sum()13 count_tinh = ((df[khoi] >= score[khoi].iloc[0]) & (df['tinh'] == score['tinh'].iloc[0])).sum()14 15 count_all_noscore = (df[khoi] >= 0).sum()16 count_kv_noscore = ((df[khoi] >= 0) & (df['kv'] == score['kv'].iloc[0])).sum()17 count_tinh_noscore = ((df[khoi] >= 0) & (df['tinh'] == score['tinh'].iloc[0])).sum()18 19 return f"""Tổng điểm theo khối {khoi} của bạn là: {score[khoi].iloc[0]}20 Thứ hạng toàn quốc: {count_all} / {count_all_noscore}21 Thứ hạng theo khu vực: {count_kv} / {count_kv_noscore}22 Thứ hạng theo tỉnh: {count_tinh} / {count_tinh_noscore}""", score.iloc[:, 1:10]23 24"""25Chatbot26"""27with gr.Blocks() as demo:28 gr.Markdown(29 """30 <style>31 .gr-button-secondary {32 width: 100px;33 height: 30px;34 padding: 5px;35 }36 .gr-row {37 display: flex;38 align-items: center;39 gap: 10px;40 }41 .gr-block {42 padding: 20px;43 }44 .gr-markdown p {45 font-size: 16px;46 }47 </style>48 <span style='font-family: Arial, sans-serif; font-size: 20px;'>Xếp hạng điểm thi Tốt nghiệp THPT 2024</span>49 <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>50 """51 )52 with gr.Row():53 id = gr.Textbox(placeholder="Nhập SBD của bạn", label="Nhập SBD của bạn:", lines=1)54 comb = gr.Dropdown(55 ["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..."56 )57 58 with gr.Row():59 check_button = gr.Button("Tra cứu!", variant="primary")60 61 dfShow = gr.DataFrame(label="Điểm thi", col_count=(9, "fixed"), row_count=(1, "fixed"))62 out = gr.Textbox(label="Xếp hạng", placeholder="", lines=2)63 64 check_button.click(fn=respond, inputs=[id,comb], outputs=[out,dfShow])65 66 gr.Markdown(67 """68 <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>69 """70 )71 72if __name__ == "__main__":73 demo.launch()