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" new_data=[2,'OK'] 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 save_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): results='登陆成功,存储报告成功。' user_data_df.loc[len(user_data_df)]=[username,datetime.date.today(), datetime.datetime.now().strftime('%H:%M:%S'), new_data[0], new_data[1] ] user_data_df.to_csv('./user_data/data.csv',encoding='gbk',index=False) elif(is_usn): results='密码错误!' else: user_login_df.loc[len(user_login_df)]=[username,password] user_data_df.loc[len(user_data_df)]=[username,datetime.date.today(), datetime.datetime.now().strftime('%H:%M:%S'), new_data[0], new_data[1] ] user_login_df.to_csv('./user_login/login.csv',encoding='gbk',index=False) user_data_df.to_csv('./user_data/data.csv',encoding='gbk',index=False) results='账户不存在,已创建新的账户。' return results page1=gr.Interface(fn=read_ui,inputs=[gr.Textbox(label="用户名:"),gr.Textbox(label="密码:")],outputs="text",title='登录以读取报告') page2=gr.Interface(fn=save_ui,inputs=[gr.Textbox(label="用户名:"),gr.Textbox(label="密码:")],outputs="text",title='登录以存储当前报告') page1.render() page2.render()