File size: 2,969 Bytes
fae2f17 4e79507 fae2f17 33c8dfc fae2f17 4e79507 fae2f17 33c8dfc fae2f17 2e00288 8473d93 2e00288 fae2f17 4e79507 fae2f17 4e79507 8473d93 4e79507 8473d93 4e79507 8473d93 4e79507 8473d93 fae2f17 ce5719d 8473d93 4e79507 19f29a8 fae2f17 7dd841c fae2f17 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
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() |