Spaces:
Runtime error
Runtime error
File size: 2,305 Bytes
7950af4 |
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 74 75 76 77 78 79 80 81 82 |
# 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,
)
|