Liusuthu's picture
upload main part
7950af4 verified
raw
history blame
2.31 kB
# import datetime
import os
import gradio as gr
import numpy as np
import pandas as pd
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
def read_ui(username, password):
user_login_df = pd.read_csv(
"./user_login/login.csv", encoding="gbk", converters={"password": str}
)
user_login = user_login_df.set_index("username")["password"].T.to_dict()
user_data_df = pd.read_csv("./user_data/data.csv", encoding="gbk")
results = ""
is_usn = username in user_login
if is_usn:
pswd_crct = password == user_login[username]
if is_usn and pswd_crct:
report = user_data_df[user_data_df["username"] == username]
report = np.array(report).tolist()
results = "用户名:" + username + "\n"
for i in range(len(report)):
line = report[i]
results = (
results
+ "第"
+ str(i + 1)
+ "次测试 "
+ "日期:"
+ str(line[1])
+ " 时间:"
+ str(line[2])
+ "评分:"
+ str(line[3])
+ " 评语:"
+ str(line[4])
+ "\n"
)
elif is_usn:
results = "密码错误,无法读取报告数据。"
else:
results = "账户不存在,无法读取报告数据。"
return results
def clear_info():
return (
gr.Textbox(""),
gr.Textbox(""),
gr.Textbox(""),
)
with gr.Blocks() as get_user_data:
with gr.Row():
gr.HTML("<h3 style='text-align:center;'>输入账号密码查看个人历史记录</h3>")
with gr.Row():
with gr.Column(scale=1):
input_name = gr.Textbox(label="用户名")
input_pwd = gr.Textbox(label="密码")
with gr.Row():
clear_button = gr.Button("清除")
login_button = gr.Button("登录")
with gr.Column(scale=1):
output_info = gr.Textbox(label="输出", lines=5)
clear_button.click(
fn=clear_info,
inputs=[],
outputs=[input_name, input_pwd, output_info],
)
login_button.click(
fn=read_ui,
inputs=[input_name, input_pwd],
outputs=output_info,
)