Spaces:
Runtime error
Runtime error
Rename get_user_data.py to user_center.py
Browse files- get_user_data.py +0 -81
- user_center.py +133 -0
get_user_data.py
DELETED
@@ -1,81 +0,0 @@
|
|
1 |
-
# import datetime
|
2 |
-
import os
|
3 |
-
|
4 |
-
import gradio as gr
|
5 |
-
import numpy as np
|
6 |
-
import pandas as pd
|
7 |
-
|
8 |
-
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
9 |
-
|
10 |
-
|
11 |
-
def read_ui(username, password):
|
12 |
-
user_login_df = pd.read_csv(
|
13 |
-
"./user_login/login.csv", encoding="gbk", converters={"password": str}
|
14 |
-
)
|
15 |
-
user_login = user_login_df.set_index("username")["password"].T.to_dict()
|
16 |
-
user_data_df = pd.read_csv("./user_data/data.csv", encoding="gbk")
|
17 |
-
|
18 |
-
results = ""
|
19 |
-
is_usn = username in user_login
|
20 |
-
if is_usn:
|
21 |
-
pswd_crct = password == user_login[username]
|
22 |
-
if is_usn and pswd_crct:
|
23 |
-
report = user_data_df[user_data_df["username"] == username]
|
24 |
-
report = np.array(report).tolist()
|
25 |
-
results = "用户名:" + username + "\n"
|
26 |
-
for i in range(len(report)):
|
27 |
-
line = report[i]
|
28 |
-
results = (
|
29 |
-
results
|
30 |
-
+ "第"
|
31 |
-
+ str(i + 1)
|
32 |
-
+ "次测试 "
|
33 |
-
+ "日期:"
|
34 |
-
+ str(line[1])
|
35 |
-
+ " 时间:"
|
36 |
-
+ str(line[2])
|
37 |
-
+ "评分:"
|
38 |
-
+ str(line[3])
|
39 |
-
+ " 评语:"
|
40 |
-
+ str(line[4])
|
41 |
-
+ "\n"
|
42 |
-
)
|
43 |
-
elif is_usn:
|
44 |
-
results = "密码错误,无法读取报告数据。"
|
45 |
-
else:
|
46 |
-
results = "账户不存在,无法读取报告数据。"
|
47 |
-
|
48 |
-
return results
|
49 |
-
|
50 |
-
|
51 |
-
def clear_info():
|
52 |
-
return (
|
53 |
-
gr.Textbox(""),
|
54 |
-
gr.Textbox(""),
|
55 |
-
gr.Textbox(""),
|
56 |
-
)
|
57 |
-
|
58 |
-
|
59 |
-
with gr.Blocks() as get_user_data:
|
60 |
-
with gr.Row():
|
61 |
-
gr.HTML("<h3 style='text-align:center;'>输入账号密码查看个人历史记录</h3>")
|
62 |
-
with gr.Row():
|
63 |
-
with gr.Column(scale=1):
|
64 |
-
input_name = gr.Textbox(label="用户名")
|
65 |
-
input_pwd = gr.Textbox(label="密码")
|
66 |
-
with gr.Row():
|
67 |
-
clear_button = gr.Button("清除")
|
68 |
-
login_button = gr.Button("登录")
|
69 |
-
with gr.Column(scale=1):
|
70 |
-
output_info = gr.Textbox(label="输出", lines=5)
|
71 |
-
|
72 |
-
clear_button.click(
|
73 |
-
fn=clear_info,
|
74 |
-
inputs=[],
|
75 |
-
outputs=[input_name, input_pwd, output_info],
|
76 |
-
)
|
77 |
-
login_button.click(
|
78 |
-
fn=read_ui,
|
79 |
-
inputs=[input_name, input_pwd],
|
80 |
-
outputs=output_info,
|
81 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user_center.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import datetime
|
2 |
+
import os
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import numpy as np
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
9 |
+
#######################################################################################
|
10 |
+
def read_ui(username,password):
|
11 |
+
if (username=='' or password==''):
|
12 |
+
return '请填写完整信息'
|
13 |
+
user_login_df=pd.read_csv('./user_login/login.csv',encoding='gbk',converters = {'password':str})
|
14 |
+
user_login=user_login_df.set_index('username')['password'].T.to_dict()
|
15 |
+
user_data1_df=pd.read_csv('./user_data/data_1.csv',encoding='gbk')
|
16 |
+
user_data2_df=pd.read_csv('./user_data/data_2.csv',encoding='gbk',converters ={'senti_flt':float,'hobby_flt':float,'all_flt':float})
|
17 |
+
|
18 |
+
results=''
|
19 |
+
is_usn=(username in user_login)
|
20 |
+
if(is_usn):
|
21 |
+
pswd_crct=(password==user_login[username])
|
22 |
+
if(is_usn and pswd_crct):
|
23 |
+
report1=user_data1_df[user_data1_df['username'] == username]
|
24 |
+
report1=np.array(report1).tolist()
|
25 |
+
report2=user_data2_df[user_data2_df['username'] == username]
|
26 |
+
report2=np.array(report2).tolist()
|
27 |
+
|
28 |
+
results='用户名:'+username+'\n'
|
29 |
+
for i in range(len(report1)):
|
30 |
+
line1=report1[i]
|
31 |
+
results=results+'第'+str(i+1)+'次量表测试 '+'日期:'+str(line1[1])+' 时间:'+str(line1[2])+'\n'
|
32 |
+
results=results+'量表分数:'+str(line1[3])+' 结果解释:'+line1[4]+' 建议:'+line1[5]+'\n'
|
33 |
+
results+='\n'
|
34 |
+
|
35 |
+
|
36 |
+
for i in range (len(report2)):
|
37 |
+
line2=report2[i]
|
38 |
+
results=results+'第'+str(i+1)+'次咨询 '+'日期:'+str(line2[1])+' 时间:'+str(line2[2])+'\n'
|
39 |
+
results=results+'睡眠情况:'+str(line2[3])+' 食欲情况:'+str(line2[4])+' 情绪情况:'+str(line2[5])+' 情绪分数:'+str(line2[6])+' 情绪回答:'+str(line2[7])+' 轻生倾向:'+str(line2[8])+'\n'
|
40 |
+
results=results+'兴趣爱好分数:'+str(line2[9])+' 兴趣爱好回答:'+line2[10]+' 近期总体分数:'+str(line2[11])+' 近期总体回答:'+line2[12]+'\n'+'最终建议:'+line2[13]+'\n\n'
|
41 |
+
|
42 |
+
elif(is_usn):
|
43 |
+
results='密码错误,无法读取报告数据。'
|
44 |
+
else:
|
45 |
+
results='账户不存在,无法读取报告数据。'
|
46 |
+
|
47 |
+
|
48 |
+
return results
|
49 |
+
|
50 |
+
|
51 |
+
def delete_ui(username,password):
|
52 |
+
if (username=='' or password==''):
|
53 |
+
return '请填写完整信息'
|
54 |
+
user_login_df=pd.read_csv('./user_login/login.csv',encoding='gbk',converters = {'password':str})
|
55 |
+
user_login=user_login_df.set_index('username')['password'].T.to_dict()
|
56 |
+
user_data1_df=pd.read_csv('./user_data/data_1.csv',encoding='gbk')
|
57 |
+
user_data2_df=pd.read_csv('./user_data/data_2.csv',encoding='gbk',converters ={'senti_flt':float,'hobby_flt':float,'all_flt':float})
|
58 |
+
|
59 |
+
results=''
|
60 |
+
is_usn=(username in user_login)
|
61 |
+
if(is_usn):
|
62 |
+
pswd_crct=(password==user_login[username])
|
63 |
+
if(is_usn and pswd_crct):
|
64 |
+
user_data1_df.drop(user_data1_df[user_data1_df['username'] == username].index,inplace=True)
|
65 |
+
user_data2_df.drop(user_data2_df[user_data2_df['username'] == username].index,inplace=True)
|
66 |
+
user_login_df.drop(user_login_df[user_login_df['username'] == username].index,inplace=True)
|
67 |
+
user_login_df.to_csv('./user_login/login.csv',encoding='gbk',index=False)
|
68 |
+
user_data1_df.to_csv('./user_data/data_1.csv',encoding='gbk',index=False)
|
69 |
+
user_data2_df.to_csv('./user_data/data_2.csv',encoding='gbk',index=False)
|
70 |
+
results='已删除对应账户所有数据'
|
71 |
+
|
72 |
+
elif(is_usn):
|
73 |
+
results='密码错误,无法删除报告数据。'
|
74 |
+
else:
|
75 |
+
results='账户不存在,无法删除报告数据。'
|
76 |
+
return results
|
77 |
+
|
78 |
+
###########################################################################################
|
79 |
+
def clear_info():
|
80 |
+
return (
|
81 |
+
gr.Textbox(""),
|
82 |
+
gr.Textbox(""),
|
83 |
+
gr.Textbox(""),
|
84 |
+
)
|
85 |
+
|
86 |
+
|
87 |
+
with gr.Blocks() as user_center:
|
88 |
+
with gr.Tab("查询历史"):
|
89 |
+
with gr.Row():
|
90 |
+
gr.HTML("<h3 style='text-align:center;'>输入账号密码查看个人历史记录</h3>")
|
91 |
+
with gr.Row():
|
92 |
+
with gr.Column(scale=1):
|
93 |
+
input_name1 = gr.Textbox(label="用户名")
|
94 |
+
input_pwd1 = gr.Textbox(label="密码")
|
95 |
+
with gr.Row():
|
96 |
+
clear_button1 = gr.Button("清除")
|
97 |
+
login_button1 = gr.Button("登录")
|
98 |
+
with gr.Column(scale=1):
|
99 |
+
output_info1 = gr.Textbox(label="输出", lines=5)
|
100 |
+
with gr.Tab("清空数据"):
|
101 |
+
with gr.Row():
|
102 |
+
gr.HTML("<h3 style='text-align:center;'>输入账号密码清空个人历史记录与账号</h3>")
|
103 |
+
with gr.Row():
|
104 |
+
with gr.Column(scale=1):
|
105 |
+
input_name2 = gr.Textbox(label="用户名")
|
106 |
+
input_pwd2 = gr.Textbox(label="密码")
|
107 |
+
with gr.Row():
|
108 |
+
clear_button2 = gr.Button("清除")
|
109 |
+
delete_button2 = gr.Button("登录")
|
110 |
+
with gr.Column(scale=1):
|
111 |
+
output_info2 = gr.Textbox(label="输出", lines=5)
|
112 |
+
|
113 |
+
|
114 |
+
clear_button1.click(
|
115 |
+
fn=clear_info,
|
116 |
+
inputs=[],
|
117 |
+
outputs=[input_name1, input_pwd1, output_info],
|
118 |
+
)
|
119 |
+
login_button1.click(
|
120 |
+
fn=read_ui,
|
121 |
+
inputs=[input_name, input_pwd],
|
122 |
+
outputs=output_info,
|
123 |
+
)
|
124 |
+
clear_button2.click(
|
125 |
+
fn=clear_info,
|
126 |
+
inputs=[],
|
127 |
+
outputs=[input_name2, input_pwd2, output_info2],
|
128 |
+
)
|
129 |
+
delete_button2.click(
|
130 |
+
fn=delete_ui,
|
131 |
+
inputs=[],
|
132 |
+
outputs=[output_info2],
|
133 |
+
)
|