Spaces:
Runtime error
Runtime error
upload main part
Browse files- chat.py +100 -0
- consult.py +256 -0
- consult_func.py +185 -0
- details.py +26 -0
- get_user_data.py +81 -0
- introduce.html +19 -0
- introduce.py +20 -0
- login_ui.py +73 -0
- mainapp.py +58 -0
- scale.py +71 -0
- test.py +20 -0
- user_data/data.csv +6 -0
- user_login/login.csv +5 -0
chat.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
6 |
+
|
7 |
+
# from paddlenlp import Taskflow
|
8 |
+
|
9 |
+
|
10 |
+
def visibility(choice):
|
11 |
+
if choice == "不好":
|
12 |
+
return gr.Column(visible=True), gr.Radio(visible=False)
|
13 |
+
else:
|
14 |
+
return gr.Column(visible=False), gr.Radio(visible=True)
|
15 |
+
|
16 |
+
|
17 |
+
def visibility2():
|
18 |
+
return gr.Radio(visible=True)
|
19 |
+
|
20 |
+
|
21 |
+
def visibility3(choice):
|
22 |
+
if choice == "不好":
|
23 |
+
return gr.Column(visible=True), gr.Column(visible=False)
|
24 |
+
else:
|
25 |
+
return gr.Column(visible=False), gr.Column(visible=True)
|
26 |
+
|
27 |
+
|
28 |
+
def visibility4():
|
29 |
+
return gr.Column(visible=True)
|
30 |
+
|
31 |
+
|
32 |
+
def visibility5(choice):
|
33 |
+
if choice == "不好":
|
34 |
+
return (
|
35 |
+
gr.Column(visible=True),
|
36 |
+
gr.Column(visible=False),
|
37 |
+
gr.Column(visible=False),
|
38 |
+
)
|
39 |
+
else:
|
40 |
+
return (
|
41 |
+
gr.Column(visible=False),
|
42 |
+
gr.Column(visible=False),
|
43 |
+
gr.Column(visible=True),
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
def advice(ans1, ans2, ans3, ans4, ans5, ans6):
|
48 |
+
return gr.Textbox(visible=True, value="结束~")
|
49 |
+
|
50 |
+
|
51 |
+
with gr.Blocks() as chat:
|
52 |
+
gr.Markdown("让我们来聊聊天吧~")
|
53 |
+
with gr.Column():
|
54 |
+
radio1 = gr.Radio(["好", "不好"], label="你最近睡眠还好吗?")
|
55 |
+
with gr.Column(visible=False) as q1:
|
56 |
+
ans1 = gr.Textbox(
|
57 |
+
label="你入睡的时间一般在几点?一直持续地睡到几点醒来?醒来后是否还能入睡?"
|
58 |
+
)
|
59 |
+
with gr.Accordion(label="示例"):
|
60 |
+
gr.Markdown(
|
61 |
+
"我睡眠还好/我最近睡眠不太好,有点失眠/我最近睡眠不好,容易早醒"
|
62 |
+
)
|
63 |
+
btn1 = gr.Button("继续")
|
64 |
+
radio2 = gr.Radio(["好", "不好"], label="你最近食欲还好吗?", visible=False)
|
65 |
+
with gr.Column(visible=False) as q2:
|
66 |
+
ans2 = gr.Textbox(label="你体重上有什么变化吗?比如说增重或消瘦?")
|
67 |
+
with gr.Accordion(label="示例"):
|
68 |
+
gr.Markdown("")
|
69 |
+
btn2 = gr.Button("继续")
|
70 |
+
radio3 = gr.Radio(["好", "不好"], label="你最近心情还好吗?", visible=False)
|
71 |
+
with gr.Column(visible=False) as q3:
|
72 |
+
ans3 = gr.Textbox(label="你心情不好持续了多长时间呢?有在两周以上吗?")
|
73 |
+
with gr.Accordion(label="示例"):
|
74 |
+
gr.Markdown("")
|
75 |
+
btn3 = gr.Button("继续")
|
76 |
+
with gr.Column(visible=False) as q4:
|
77 |
+
ans4 = gr.Textbox(
|
78 |
+
label="你这段时间真的很不容易,愿意和我说说吗?说什么都可以,也许倾诉出来会好一些呢"
|
79 |
+
)
|
80 |
+
btn4 = gr.Button("抱抱你")
|
81 |
+
with gr.Column(visible=False) as q5:
|
82 |
+
ans5 = gr.Textbox(
|
83 |
+
label="你有什么兴趣爱好吗?平常都喜欢干什么事情呢?愿意和我说说吗?"
|
84 |
+
)
|
85 |
+
btn5 = gr.Button("继续")
|
86 |
+
with gr.Column(visible=False) as q6:
|
87 |
+
ans6 = gr.Textbox(
|
88 |
+
label="5.你愿意和我聊聊你最近都喜欢干些什么,或者有什么事情让你很沉浸,感到开心或者觉得很有意义吗?还有那些让你觉得自己很厉害,很有成就感的事情,比如说你做成了什么有难度的事情或者帮助了谁?什么都可以哦"
|
89 |
+
)
|
90 |
+
btn6 = gr.Button("提交")
|
91 |
+
adv = gr.Textbox(visible=False)
|
92 |
+
radio1.change(visibility, radio1, [q1, radio2])
|
93 |
+
btn1.click(visibility2, outputs=radio2)
|
94 |
+
radio2.change(visibility, radio2, [q2, radio3])
|
95 |
+
btn2.click(visibility2, outputs=radio3)
|
96 |
+
radio3.change(visibility5, radio3, [q3, q4, q5])
|
97 |
+
btn3.click(visibility4, outputs=q4)
|
98 |
+
btn4.click(visibility4, outputs=q5)
|
99 |
+
btn5.click(visibility4, outputs=q6)
|
100 |
+
btn6.click(advice, [ans1, ans2, ans3, ans4, ans5, ans6], adv)
|
consult.py
ADDED
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from consult_func import (
|
4 |
+
advice,
|
5 |
+
visibility,
|
6 |
+
visibility3,
|
7 |
+
visibility4,
|
8 |
+
visibility_choice,
|
9 |
+
visibility_choice2,
|
10 |
+
visibility_choice3,
|
11 |
+
visibility_choice4,
|
12 |
+
visibility_choice5,
|
13 |
+
)
|
14 |
+
|
15 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
16 |
+
|
17 |
+
# constants
|
18 |
+
schema = "情感倾向[正向,负向]" # Define the schema for sentence-level sentiment classification
|
19 |
+
# 定义音频模态下权重
|
20 |
+
weight_speech = 0.2
|
21 |
+
weight_text = 0.8
|
22 |
+
# 定义视频模态下权重
|
23 |
+
weight_video = 0.3
|
24 |
+
weight_speech2 = 0.1
|
25 |
+
weight_text2 = 0.6
|
26 |
+
|
27 |
+
|
28 |
+
# scores
|
29 |
+
score1 = 0 # 第一道问答题:你这段时间真的很不容易,愿意和我说说吗?说什么都可以,也许倾诉出来会好一些呢
|
30 |
+
score2 = 0 # 第二道问答题:你有什么兴趣爱好吗?平常都喜欢干什么事情呢?愿意和我说说吗?
|
31 |
+
score3 = 0 # 第三道问答题:
|
32 |
+
|
33 |
+
# video model
|
34 |
+
|
35 |
+
|
36 |
+
# speech model
|
37 |
+
|
38 |
+
|
39 |
+
# text model
|
40 |
+
# ie = Taskflow('information_extraction', schema=schema, model='uie-base')
|
41 |
+
|
42 |
+
# 以下为调用语音模型
|
43 |
+
|
44 |
+
|
45 |
+
with gr.Blocks() as consult:
|
46 |
+
gr.Markdown(
|
47 |
+
"欢迎来到这里,接下来我们来放松地聊聊天,你只要如实完整地回答我的问题就好了。"
|
48 |
+
)
|
49 |
+
btn1 = gr.Button("开始")
|
50 |
+
with gr.Column(visible=False) as questions:
|
51 |
+
# 睡眠问题
|
52 |
+
title1 = gr.Markdown("# 睡眠")
|
53 |
+
radio1 = gr.Radio(
|
54 |
+
["充足", "不足"],
|
55 |
+
label="你最近睡眠还充足吗?",
|
56 |
+
type="index",
|
57 |
+
interactive=True,
|
58 |
+
)
|
59 |
+
with gr.Column(visible=False) as q1_1:
|
60 |
+
radio2 = gr.Radio(
|
61 |
+
["存在", "不存在"],
|
62 |
+
label="你会存在嗜睡的情况吗?比如容易一直睡过整个上午甚至一直持续睡到下午?",
|
63 |
+
interactive=True,
|
64 |
+
)
|
65 |
+
with gr.Column(visible=False) as q1_2:
|
66 |
+
radio3 = gr.Radio(
|
67 |
+
["不存在", "失眠", "早醒"],
|
68 |
+
label="你是否存在失眠或早醒的情况?",
|
69 |
+
interactive=True,
|
70 |
+
)
|
71 |
+
adv1 = gr.Textbox(visible=False)
|
72 |
+
|
73 |
+
# 饮食问题
|
74 |
+
title2 = gr.Markdown("# 饮食", visible=False)
|
75 |
+
radio4 = gr.Radio(
|
76 |
+
[
|
77 |
+
"食欲正常,没有体重上的明显变化",
|
78 |
+
"食欲亢进,体重增加",
|
79 |
+
"食欲不振,体重减轻",
|
80 |
+
],
|
81 |
+
type="index",
|
82 |
+
label="你最近食欲如何?有任何体重上的变化吗?",
|
83 |
+
visible=False,
|
84 |
+
interactive=True,
|
85 |
+
)
|
86 |
+
|
87 |
+
# 情绪问题
|
88 |
+
title3 = gr.Markdown("# 情绪", visible=False)
|
89 |
+
radio5 = gr.Radio(
|
90 |
+
["好", "不好"], label="你最近心情还好吗?", visible=False, interactive=True
|
91 |
+
)
|
92 |
+
radio6 = gr.Radio(
|
93 |
+
["一周以内", "一周至两周", "两周以上"],
|
94 |
+
label="你心情不好持续了多长时间呢?",
|
95 |
+
visible=False,
|
96 |
+
interactive=True,
|
97 |
+
)
|
98 |
+
with gr.Column(visible=False) as q3_2:
|
99 |
+
gr.Markdown(
|
100 |
+
"你这段时间真的很不容易,愿意和我说说吗?说什么都可以,也许倾诉出来会好一些呢"
|
101 |
+
)
|
102 |
+
radio7 = gr.Radio(
|
103 |
+
["文本", "语音", "视频"],
|
104 |
+
label="请选择以哪种方式回答",
|
105 |
+
type="index",
|
106 |
+
interactive=True,
|
107 |
+
)
|
108 |
+
with gr.Column(visible=False) as ans3_1: # 文本回答
|
109 |
+
text3_1 = gr.Textbox(interactive=True)
|
110 |
+
btn3_1 = gr.Button("抱抱你")
|
111 |
+
# 请把audio3_2换成Audio组件
|
112 |
+
with gr.Column(visible=False) as ans3_2: # 语音回答
|
113 |
+
audio3_2 = gr.Textbox(
|
114 |
+
label="抑郁概率", interactive=True
|
115 |
+
) # 对应out_prob.squeeze(0).numpy()[0]
|
116 |
+
btn3_2 = gr.Button("抱抱你")
|
117 |
+
# 请把video3_3换成Video组件
|
118 |
+
with gr.Column(visible=False) as ans3_3: # 视频回答
|
119 |
+
with gr.Row() as video3_3:
|
120 |
+
# 我也不知道以下这些概率如何调用,你知道就好
|
121 |
+
emo0_3_3 = gr.Textbox(label="Neutral", interactive=True)
|
122 |
+
emo1_3_3 = gr.Textbox(label="Happiness", interactive=True)
|
123 |
+
emo2_3_3 = gr.Textbox(label="Sadness", interactive=True)
|
124 |
+
emo3_3_3 = gr.Textbox(label="Surprise", interactive=True)
|
125 |
+
emo4_3_3 = gr.Textbox(label="Fear", interactive=True)
|
126 |
+
emo5_3_3 = gr.Textbox(label="Disgust", interactive=True)
|
127 |
+
emo6_3_3 = gr.Textbox(label="Anger", interactive=True)
|
128 |
+
btn3_3 = gr.Button("抱抱你")
|
129 |
+
# 自杀倾向问题
|
130 |
+
radio8 = gr.Radio(
|
131 |
+
["想过", "没想过"],
|
132 |
+
label="你想过死吗?",
|
133 |
+
visible=False,
|
134 |
+
type="index",
|
135 |
+
interactive=True,
|
136 |
+
)
|
137 |
+
radio9 = gr.Radio(
|
138 |
+
["想过", "没想过"],
|
139 |
+
label="那你想过怎么死吗?",
|
140 |
+
visible=False,
|
141 |
+
type="index",
|
142 |
+
interactive=True,
|
143 |
+
)
|
144 |
+
radio10 = gr.Radio(
|
145 |
+
[
|
146 |
+
"没想过",
|
147 |
+
"想过,没想过具体时间和地点",
|
148 |
+
"想过具体做法,时间和地点,没实践过",
|
149 |
+
"实践过",
|
150 |
+
],
|
151 |
+
label="那你想过具体的做法吗?",
|
152 |
+
visible=False,
|
153 |
+
)
|
154 |
+
dead_hug = gr.Markdown(
|
155 |
+
"很抱歉听到这些话,我们非常理解并关心你的情绪,我们明白产生自杀念头的原因是复杂的,并不是你的过错。如果你愿意的话,可以多来找我们聊聊天,我们愿意充当你的知心好友,并且承诺对你说的所有话严格保密。如果可以的话,我们还建议你积极寻求专业心理医生的帮助,和他们聊聊天,讲讲自己的感受。加油!\n",
|
156 |
+
visible=False,
|
157 |
+
)
|
158 |
+
|
159 |
+
# 兴趣爱好
|
160 |
+
with gr.Column(visible=False) as q4:
|
161 |
+
title4 = gr.Markdown("# 兴趣爱好")
|
162 |
+
gr.Markdown("你有什么兴趣爱好吗?平常都喜欢干什么事情呢?愿意和我说说吗?")
|
163 |
+
radio11 = gr.Radio(
|
164 |
+
["文本", "语音", "视频"],
|
165 |
+
label="请选择以哪种方式回答",
|
166 |
+
type="index",
|
167 |
+
interactive=True,
|
168 |
+
)
|
169 |
+
with gr.Column(visible=False) as ans4_1:
|
170 |
+
text4_1 = gr.Textbox(interactive=True)
|
171 |
+
btn4_1 = gr.Button("继续")
|
172 |
+
result4_1 = gr.Textbox(label="结果4_1")
|
173 |
+
# 请把audio4_2换成Audio组件
|
174 |
+
with gr.Column(visible=False) as ans4_2:
|
175 |
+
audio4_2 = gr.Audio(
|
176 |
+
label="语音录制", interactive=True, sources=["microphone"]
|
177 |
+
) # 对应out_prob.squeeze(0).numpy()[0]
|
178 |
+
btn4_2 = gr.Button("继续")
|
179 |
+
result4_2 = gr.Textbox(label="结果4_2")
|
180 |
+
# 请把video4_3换成Video组件
|
181 |
+
with gr.Column(visible=False) as ans4_3:
|
182 |
+
video4_3 = gr.Video(sources=["webcam", "upload"],interactive=True,)
|
183 |
+
btn4_3 = gr.Button("继续")
|
184 |
+
result4_3 = gr.Textbox(label="结果4_3")
|
185 |
+
|
186 |
+
# 针对无价值感、无意义感、无力感
|
187 |
+
|
188 |
+
with gr.Column(visible=False) as q5:
|
189 |
+
title5 = gr.Markdown("# 近期情况")
|
190 |
+
gr.Markdown(
|
191 |
+
"你愿意和我聊聊你最近都喜欢干些什么,或者有什么事情让你很沉浸,感到开心或者觉得很有意义吗?还有那些让你觉得自己很厉害,很有成就感的事情,比如说你做成了什么有难度的事情或者帮助了谁?什么都可以哦"
|
192 |
+
)
|
193 |
+
radio12 = gr.Radio(
|
194 |
+
["文本", "语音", "视频"],
|
195 |
+
label="请选择以哪种方式回答",
|
196 |
+
type="index",
|
197 |
+
interactive=True,
|
198 |
+
)
|
199 |
+
with gr.Column(visible=False) as ans5_1:
|
200 |
+
text5_1 = gr.Textbox(interactive=True)
|
201 |
+
btn5_1 = gr.Button("提交")
|
202 |
+
result5_1 = gr.Textbox(label="结果5_1")
|
203 |
+
# 请把audio5_2换成Audio组件
|
204 |
+
with gr.Column(visible=False) as ans5_2:
|
205 |
+
audio5_2 = gr.Audio(
|
206 |
+
label="语音录制", interactive=True
|
207 |
+
) # 对应out_prob.squeeze(0).numpy()[0]
|
208 |
+
btn5_2 = gr.Button("提交")
|
209 |
+
result5_2 = gr.Textbox(label="结果5_2")
|
210 |
+
# 请把video5_3换成Video组件
|
211 |
+
with gr.Column(visible=False) as ans5_3:
|
212 |
+
# score = gr.Textbox(label="得分")
|
213 |
+
video5_3=gr.Video(sources=["webcam", "upload"],interactive=True,)
|
214 |
+
btn5_3 = gr.Button("提交")
|
215 |
+
result5_3 = gr.Textbox(label="结果5_3")
|
216 |
+
title6 = gr.Markdown("# 咨询总结与建议", visible=False)
|
217 |
+
final_score = gr.Textbox(visible=False, interactive=False)
|
218 |
+
adv = gr.Textbox(label="", visible=False)
|
219 |
+
|
220 |
+
btn1.click(visibility, outputs=questions)
|
221 |
+
radio1.change(visibility_choice, radio1, [q1_1, q1_2])
|
222 |
+
radio2.change(visibility3, outputs=[title2, radio4])
|
223 |
+
radio3.change(visibility3, outputs=[title2, radio4])
|
224 |
+
radio4.change(visibility3, outputs=[title3, radio5])
|
225 |
+
radio5.change(visibility_choice3, radio5, [radio6, q3_2, q4])
|
226 |
+
radio6.change(visibility, outputs=q3_2)
|
227 |
+
radio7.change(visibility_choice2, radio7, [ans3_1, ans3_2, ans3_3])
|
228 |
+
btn3_1.click(visibility_choice5, text3_1, [radio8, q4])
|
229 |
+
# 关于btn3_2,btn3_3:请你设计一个函数把语音/视频中文本提取出来,然后经过keyword函数判定来决定要不要出现radio8
|
230 |
+
radio8.change(visibility_choice4, radio8, [radio9, q4])
|
231 |
+
radio9.change(visibility_choice4, radio9, [radio10, q4])
|
232 |
+
radio10.change(visibility, outputs=q4)
|
233 |
+
radio10.change(visibility4, outputs=dead_hug)
|
234 |
+
radio11.change(visibility_choice2, radio11, [ans4_1, ans4_2, ans4_3])
|
235 |
+
btn4_1.click(visibility, outputs=q5)
|
236 |
+
btn4_2.click(visibility, outputs=q5)
|
237 |
+
btn4_3.click(visibility, outputs=q5)
|
238 |
+
radio12.change(visibility_choice2, radio12, [ans5_1, ans5_2, ans5_3])
|
239 |
+
btn5_1.click(
|
240 |
+
advice,
|
241 |
+
[
|
242 |
+
radio1,
|
243 |
+
radio2,
|
244 |
+
radio3,
|
245 |
+
radio4,
|
246 |
+
radio5,
|
247 |
+
radio6,
|
248 |
+
text3_1,
|
249 |
+
radio8,
|
250 |
+
radio9,
|
251 |
+
radio10,
|
252 |
+
],
|
253 |
+
[title6, final_score, adv],
|
254 |
+
)
|
255 |
+
# btn5_2.click(visibility,outputs=q5)
|
256 |
+
# btn5_3.click(visibility,outputs=q5)
|
consult_func.py
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
5 |
+
|
6 |
+
def advice1(radio1, radio2, radio3):
|
7 |
+
# 有关睡眠问题的建议
|
8 |
+
if radio1 == 0:
|
9 |
+
if radio2 == "存在":
|
10 |
+
return "嗜睡"
|
11 |
+
else:
|
12 |
+
return radio2
|
13 |
+
if radio1 == 1:
|
14 |
+
return radio3
|
15 |
+
|
16 |
+
|
17 |
+
def advice2(radio4):
|
18 |
+
# 有关饮食问题的建议
|
19 |
+
if radio4 == 0:
|
20 |
+
return "不存在"
|
21 |
+
if radio4 == 1:
|
22 |
+
return "增重"
|
23 |
+
else:
|
24 |
+
return "消瘦"
|
25 |
+
|
26 |
+
|
27 |
+
def advice3(radio5, radio6):
|
28 |
+
# 有关情绪问题的建议
|
29 |
+
if radio5 == "好":
|
30 |
+
return "不存在情绪问题"
|
31 |
+
if radio5 == "不好":
|
32 |
+
return "抑郁情绪持续了" + radio6
|
33 |
+
|
34 |
+
|
35 |
+
def advice4(radio5, text3_1, radio8, radio9, radio10):
|
36 |
+
# 有关自杀倾向的建议
|
37 |
+
if radio5 == "不好":
|
38 |
+
if keyword(text3_1):
|
39 |
+
if radio8 == 0:
|
40 |
+
if radio9 == 0:
|
41 |
+
if radio10 == "没想过":
|
42 |
+
return ",有自杀倾向"
|
43 |
+
if radio10 == "想过,没想过具体时间和地点":
|
44 |
+
return ",自杀倾向较严重"
|
45 |
+
if radio10 == "想过具体做法,时间和地点,没实践过":
|
46 |
+
return ",自杀倾向严重"
|
47 |
+
if radio10 == "实践过":
|
48 |
+
return ",有过自杀行为"
|
49 |
+
else:
|
50 |
+
return ",有自杀倾向"
|
51 |
+
else:
|
52 |
+
return ""
|
53 |
+
else:
|
54 |
+
return ""
|
55 |
+
|
56 |
+
|
57 |
+
def advice(
|
58 |
+
radio1, radio2, radio3, radio4, radio5, radio6, text3_1, radio8, radio9, radio10
|
59 |
+
):
|
60 |
+
symptoms = ""
|
61 |
+
if advice1(radio1, radio2, radio3) == "不存在" and advice2(radio4) == "不存在":
|
62 |
+
symptoms = "不存在睡眠、饮食问题且"
|
63 |
+
if advice1(radio1, radio2, radio3) != "不存在" and advice2(radio4) == "不存在":
|
64 |
+
symptoms = "存在" + advice1(radio1, radio2, radio3) + "问题,不存在饮食问题且"
|
65 |
+
if advice1(radio1, radio2, radio3) == "不存在" and advice2(radio4) != "不存在":
|
66 |
+
symptoms = "不存在睡眠问题,存在" + advice2(radio4) + "问题且"
|
67 |
+
|
68 |
+
return (
|
69 |
+
gr.Markdown(visible=True),
|
70 |
+
gr.Textbox(visible=True),
|
71 |
+
gr.Textbox(
|
72 |
+
value="你"
|
73 |
+
+ symptoms
|
74 |
+
+ advice3(radio5, radio6)
|
75 |
+
+ advice4(radio5, text3_1, radio8, radio9, radio10)
|
76 |
+
+ "。\n 抑郁症症状因人而异,并不应当只以是否存在上述症状来判断,并且可能存在上述症状以外更个人化的症状,如果存在强烈的各种不适或者怀疑自己有抑郁症,建议及时去进行专业检查和干预治疗,也有可能存在抑郁症以外的各类精神障碍与心理疾病,如焦虑症或双相情感障碍等等。\n 抑郁症和其他各类精神上的疾病不是患者的问题或者错误,也不是矫情或者敏感,也不说明患者与其他人有什么不同,他们只是生病了,需要进行治疗而已。此外,一次测试结果不能代表全部,我们希望你能持续地关注自己的心理健康状态,常来这里自测评估一下。最后,不管你有没有抑郁症或者其他疾病,都拍拍你,抱抱你,祝愿你接下来的生活光明灿烂!",
|
77 |
+
visible=True,
|
78 |
+
),
|
79 |
+
)
|
80 |
+
|
81 |
+
|
82 |
+
def final_advice(
|
83 |
+
radio1, radio2, radio3, radio4, radio5, radio6, text3_1, radio8, radio9, radio10
|
84 |
+
):
|
85 |
+
return gr.Textbox(
|
86 |
+
visible=True,
|
87 |
+
value=advice(
|
88 |
+
radio1,
|
89 |
+
radio2,
|
90 |
+
radio3,
|
91 |
+
radio4,
|
92 |
+
radio5,
|
93 |
+
radio6,
|
94 |
+
text3_1,
|
95 |
+
radio8,
|
96 |
+
radio9,
|
97 |
+
radio10,
|
98 |
+
),
|
99 |
+
)
|
100 |
+
|
101 |
+
|
102 |
+
def visibility(): # 让下一部分出现
|
103 |
+
return gr.Column(visible=True)
|
104 |
+
|
105 |
+
|
106 |
+
def visibility2(): # 让下一道选择题出现
|
107 |
+
return gr.Radio(visible=True)
|
108 |
+
|
109 |
+
|
110 |
+
def visibility3(): # 针对有标题切换的情况
|
111 |
+
return (
|
112 |
+
gr.Markdown(visible=True),
|
113 |
+
gr.Radio(visible=True),
|
114 |
+
)
|
115 |
+
|
116 |
+
|
117 |
+
def visibility4():
|
118 |
+
return gr.Markdown(visible=True)
|
119 |
+
|
120 |
+
|
121 |
+
def visibility_choice(choice): # 根据选择选项的不同决定下一道题是哪个
|
122 |
+
if choice == 0:
|
123 |
+
return gr.Column(visible=True), gr.Column(visible=False)
|
124 |
+
else:
|
125 |
+
return gr.Column(visible=False), gr.Column(visible=True)
|
126 |
+
|
127 |
+
|
128 |
+
def visibility_choice2(choice): # 选择视频,语音还是文本输入
|
129 |
+
if choice == 0:
|
130 |
+
return (
|
131 |
+
gr.Column(visible=True),
|
132 |
+
gr.Column(visible=False),
|
133 |
+
gr.Column(visible=False),
|
134 |
+
)
|
135 |
+
if choice == 1:
|
136 |
+
return (
|
137 |
+
gr.Column(visible=False),
|
138 |
+
gr.Column(visible=True),
|
139 |
+
gr.Column(visible=False),
|
140 |
+
)
|
141 |
+
else:
|
142 |
+
return (
|
143 |
+
gr.Column(visible=False),
|
144 |
+
gr.Column(visible=False),
|
145 |
+
gr.Column(visible=True),
|
146 |
+
)
|
147 |
+
|
148 |
+
|
149 |
+
def visibility_choice3(choice): # 根据选择选项的不同决定下一道���是哪个
|
150 |
+
if choice == "不好":
|
151 |
+
return (
|
152 |
+
gr.Radio(visible=True),
|
153 |
+
gr.Column(visible=False),
|
154 |
+
gr.Column(visible=False),
|
155 |
+
)
|
156 |
+
else:
|
157 |
+
return (
|
158 |
+
gr.Radio(visible=False),
|
159 |
+
gr.Column(visible=False),
|
160 |
+
gr.Column(visible=True),
|
161 |
+
)
|
162 |
+
|
163 |
+
|
164 |
+
def visibility_choice4(choice): # 根据选择选项的不同决定下一道题是哪个
|
165 |
+
if choice == 0:
|
166 |
+
return gr.Radio(visible=True), gr.Radio(visible=False)
|
167 |
+
else:
|
168 |
+
return gr.Radio(visible=False), gr.Radio(visible=True)
|
169 |
+
|
170 |
+
|
171 |
+
def keyword(
|
172 |
+
text,
|
173 |
+
): # 设置关于自杀倾向问题的触发词(你决定要不要加一个文本负向概率大于一定值的判定)
|
174 |
+
keywords = ["轻生", "自杀", "死", "活着", "意义", "意思", "干劲"]
|
175 |
+
for i in range(len(keywords)):
|
176 |
+
if keywords[i].find(text) != -1:
|
177 |
+
return True
|
178 |
+
return False
|
179 |
+
|
180 |
+
|
181 |
+
def visibility_choice5(text): # 关于自杀倾向问题是否触发
|
182 |
+
if keyword(text) is True:
|
183 |
+
return gr.Radio(visible=True), gr.Column(visible=False)
|
184 |
+
else:
|
185 |
+
return gr.Radio(visible=False), gr.Column(visible=True)
|
details.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
6 |
+
|
7 |
+
info = open("details_info.html", "r", encoding="utf-8")
|
8 |
+
out = ""
|
9 |
+
for i in info:
|
10 |
+
out = out + str(i)
|
11 |
+
|
12 |
+
with gr.Blocks() as details:
|
13 |
+
with gr.Row():
|
14 |
+
gr.HTML("详尽介绍")
|
15 |
+
with gr.Row():
|
16 |
+
img_inputs = ["system.png", "flow.png"]
|
17 |
+
gr.Gallery(
|
18 |
+
img_inputs,
|
19 |
+
selected_index=0,
|
20 |
+
# label="点击图片查看详情",
|
21 |
+
# show_label=True,
|
22 |
+
)
|
23 |
+
|
24 |
+
with gr.Row():
|
25 |
+
gr.HTML(out)
|
26 |
+
# 看上去还是不太能简单地进行文件输入啊,并且HTML比md方便
|
get_user_data.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
)
|
introduce.html
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<title></title>
|
6 |
+
<style>
|
7 |
+
p {text-indent:0em;}
|
8 |
+
</style>
|
9 |
+
</head>
|
10 |
+
<body>
|
11 |
+
<h1>简要介绍</h1>
|
12 |
+
<p>一个用于抑郁症倾向自测的小系统,有"量表"与"咨询"两种模式,并可创建账号并查看历史记录。
|
13 |
+
我们将严格保护您的隐私。
|
14 |
+
</p>
|
15 |
+
<br><br><br>
|
16 |
+
<h1>功能面板</h1>
|
17 |
+
</body>
|
18 |
+
</html>
|
19 |
+
|
introduce.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
INTRODUCE = """
|
2 |
+
<!DOCTYPE html>
|
3 |
+
<html>
|
4 |
+
<head>
|
5 |
+
<meta charset="utf-8" />
|
6 |
+
<title></title>
|
7 |
+
<style>
|
8 |
+
p {text-indent:0em;}
|
9 |
+
</style>
|
10 |
+
</head>
|
11 |
+
<body>
|
12 |
+
<h1>简要介绍</h1>
|
13 |
+
<p>一个用于抑郁症倾向自测的小系统,有"量表"与"咨询"两种模式,并可创建账号并查看历史记录。
|
14 |
+
我们将严格保护您的隐私。
|
15 |
+
</p>
|
16 |
+
<br><br><br>
|
17 |
+
<h1>功能面板</h1>
|
18 |
+
</body>
|
19 |
+
</html>
|
20 |
+
"""
|
login_ui.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
+
import os
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
|
8 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
9 |
+
new_data=[2,'OK']
|
10 |
+
|
11 |
+
|
12 |
+
def read_ui(username,password):
|
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_data_df=pd.read_csv('./user_data/data.csv',encoding='gbk')
|
16 |
+
|
17 |
+
results=''
|
18 |
+
is_usn=(username in user_login)
|
19 |
+
if(is_usn):
|
20 |
+
pswd_crct=(password==user_login[username])
|
21 |
+
if(is_usn and pswd_crct):
|
22 |
+
report=user_data_df[user_data_df['username'] == username]
|
23 |
+
report=np.array(report).tolist()
|
24 |
+
results='用户名:'+username+'\n'
|
25 |
+
for i in range(len(report)):
|
26 |
+
line=report[i]
|
27 |
+
results=results+'第'+str(i+1)+'次测试 '+'日期:'+str(line[1])+' 时间:'+str(line[2])+'评分:'+str(line[3])+' 评语:'+str(line[4])+'\n'
|
28 |
+
elif(is_usn):
|
29 |
+
results='密码错误,无法读取报告数据。'
|
30 |
+
else:
|
31 |
+
results='账户不存在,无法读取报告数据。'
|
32 |
+
|
33 |
+
|
34 |
+
return results
|
35 |
+
|
36 |
+
def save_ui(username,password):
|
37 |
+
user_login_df=pd.read_csv('./user_login/login.csv',encoding='gbk',converters = {'password':str})
|
38 |
+
user_login=user_login_df.set_index('username')['password'].T.to_dict()
|
39 |
+
user_data_df=pd.read_csv('./user_data/data.csv',encoding='gbk')
|
40 |
+
|
41 |
+
results=''
|
42 |
+
is_usn=(username in user_login)
|
43 |
+
if(is_usn):
|
44 |
+
pswd_crct=(password==user_login[username])
|
45 |
+
if(is_usn and pswd_crct):
|
46 |
+
results='登陆成功,存储报告成功。'
|
47 |
+
user_data_df.loc[len(user_data_df)]=[username,datetime.date.today(),
|
48 |
+
datetime.datetime.now().strftime('%H:%M:%S'),
|
49 |
+
new_data[0],
|
50 |
+
new_data[1]
|
51 |
+
]
|
52 |
+
user_data_df.to_csv('./user_data/data.csv',encoding='gbk',index=False)
|
53 |
+
elif(is_usn):
|
54 |
+
results='密码错误!'
|
55 |
+
else:
|
56 |
+
user_login_df.loc[len(user_login_df)]=[username,password]
|
57 |
+
user_data_df.loc[len(user_data_df)]=[username,datetime.date.today(),
|
58 |
+
datetime.datetime.now().strftime('%H:%M:%S'),
|
59 |
+
new_data[0],
|
60 |
+
new_data[1]
|
61 |
+
]
|
62 |
+
user_login_df.to_csv('./user_login/login.csv',encoding='gbk',index=False)
|
63 |
+
user_data_df.to_csv('./user_data/data.csv',encoding='gbk',index=False)
|
64 |
+
results='账户不存在,已创建新的账户。'
|
65 |
+
|
66 |
+
|
67 |
+
return results
|
68 |
+
|
69 |
+
|
70 |
+
page1=gr.Interface(fn=read_ui,inputs=[gr.Textbox(label="用户名:"),gr.Textbox(label="密码:")],outputs="text",title='登录以读取报告')
|
71 |
+
page2=gr.Interface(fn=save_ui,inputs=[gr.Textbox(label="用户名:"),gr.Textbox(label="密码:")],outputs="text",title='登录以存储当前报告')
|
72 |
+
page1.render()
|
73 |
+
page2.render()
|
mainapp.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
from test import test_mode
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# from acknowledge import acknowledge
|
8 |
+
# from announce import announce
|
9 |
+
# from details import details
|
10 |
+
from get_user_data import get_user_data
|
11 |
+
from introduce import INTRODUCE
|
12 |
+
|
13 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
14 |
+
|
15 |
+
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
with gr.Column():
|
18 |
+
with gr.Row():
|
19 |
+
gr.HTML(
|
20 |
+
"<h1 style='text-align:center;'>📈基于多模态融合的抑郁症检测系统📋</h1>"
|
21 |
+
)
|
22 |
+
with gr.Row():
|
23 |
+
gr.HTML("<h5 style='text-align:center;'>[_SATLab小分队]</h5>")
|
24 |
+
with gr.Row():
|
25 |
+
gr.HTML(INTRODUCE)
|
26 |
+
# with gr.Row():
|
27 |
+
# gr.HTML("<br>")
|
28 |
+
# gr.HTML("<br>")
|
29 |
+
|
30 |
+
# with gr.Row():
|
31 |
+
# gr.Markdown(
|
32 |
+
# """
|
33 |
+
# ## 下面的功能面板有五个功能,您可以自由选择。\n
|
34 |
+
# 1️⃣知情同意说明\t 2️⃣用法功能详细介绍\t 3️⃣开始自测\t 4️⃣查看个人历史数据\t 5️⃣引用与致谢\n
|
35 |
+
# """
|
36 |
+
# )
|
37 |
+
|
38 |
+
# with gr.Row():
|
39 |
+
# gr.HTML("<br>")
|
40 |
+
# gr.HTML("<br>")
|
41 |
+
# gr.HTML("<br>")
|
42 |
+
|
43 |
+
# with gr.Row():
|
44 |
+
# gr.Markdown("## 功能面板\n")
|
45 |
+
|
46 |
+
# with gr.Tab("🔈️知情同意说明"):
|
47 |
+
# announce.render()
|
48 |
+
# with gr.Tab("📜介绍"):
|
49 |
+
# details.render()
|
50 |
+
with gr.Tab("📋自我测试"):
|
51 |
+
test_mode.render()
|
52 |
+
with gr.Tab("🗃️个人中心"):
|
53 |
+
get_user_data.render()
|
54 |
+
# with gr.Tab("💐引用与致谢"):
|
55 |
+
# acknowledge.render()
|
56 |
+
|
57 |
+
|
58 |
+
demo.launch()
|
scale.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
6 |
+
|
7 |
+
s=0
|
8 |
+
|
9 |
+
def visibility():
|
10 |
+
return gr.Column(visible=True)
|
11 |
+
|
12 |
+
def Score(choice1,choice2,choice3,choice4,choice5,choice6,choice7,choice8,choice9,choice10,choice11,choice12,choice13,choice14,choice15,choice16,choice17,choice18,choice19,choice20):
|
13 |
+
score = 0
|
14 |
+
choices = [choice1,choice2,choice3,choice4,choice5,choice6,choice7,choice8,choice9,choice10,choice11,choice12,choice13,choice14,choice15,choice16,choice17,choice18,choice19,choice20]
|
15 |
+
for i in range(len(choices)):
|
16 |
+
match i:
|
17 |
+
case 1|4|5|10|11|13|15|16|17|19:
|
18 |
+
score += 4 - choices[i]
|
19 |
+
case _:
|
20 |
+
score += choices[i] + 1
|
21 |
+
global s
|
22 |
+
s = round(1.25*score, 0)
|
23 |
+
if s < 53:
|
24 |
+
return gr.Column(visible=True),s,"被测试者无抑郁体验。心情明朗,轻松愉快,对自己身体和情绪健康有良好的感受,对自己的现状感到满意。","被试无抑郁体验,希望保持。被试的生活很开心,也很轻松,感到生活充实,健康状况良好,对未来充满希望,如果条件许可,被试可以了解一些必要的心理知识,为今后保持健康的心理奠定基础。"
|
25 |
+
if 53 <= s <= 62:
|
26 |
+
return gr.Column(visible=True),s,"通过测试表明被试属于轻度抑郁。偶尔有些郁闷、压抑。被测者在遇到挫折和烦恼时,会出现暂时的情绪低落。","需要认识到这些情绪,并学习调节情绪的方法,参考建议:不要掩饰自己的负面情绪、过多地压抑自己,要学会倾诉和宣泄等方式来进行自我调节。培养积极的认知方式,改变对自己的认识,全面认识自我,悦纳自我,善待自我。"
|
27 |
+
if 63 <= s <= 72:
|
28 |
+
return gr.Column(visible=True),s,"被测试者表现出中度抑郁。你最近时常出现心境低落现象,通常情况下,继续进行工作、社交或家务活动已有一定困难。","建议从以下几方面改善抑郁状态:不草率对事件下结论;学会理性的思考方式,避免情绪性推理;避免“我必须”,“我一定”这类的自我对话;对自身做出尽可能正确和公平的评价等。学会一些自我保护措施,一旦发现自己产生了抑郁的观念或行为,可以及时运用自身力量主动挑战自己的观念和行为,如“我是否只看到了生活的黑暗面?”等;相信他人的正确评价,不要否认他人的夸奖。"
|
29 |
+
if s > 72:
|
30 |
+
return gr.Column(visible=True),s,"被测试者的测验结果为重度抑郁。从结果中可以看出,你总感到心境低落,总处于压抑、抑郁、悲伤、失望、沮丧或忧伤的情绪状态之中。你抑郁症状已十分明显,社会功能明显损害,除了在极有限的范围内,几乎不可能继续进行社交、工作或家务活动。","被测试者表现出重度抑郁。你的抑郁症状已十分明显,社会功能明显损害,除了在极有限的范围内,几乎不可能继续进行社交、工作或家务活动。应当尽快进行心理咨询"
|
31 |
+
|
32 |
+
with gr.Blocks() as scale:
|
33 |
+
with gr.Column():
|
34 |
+
gr.Markdown("本评定量表共有20个项目,请您根据最近一星期以来你的实际感受,选择一个与您的情况最相符合的答案。")
|
35 |
+
gr.Markdown("A:从无或偶尔(过去一周内,出现这类情况的日子不超过一天)")
|
36 |
+
gr.Markdown("B:有时(过去一周内,有1-2天有过这类情况)")
|
37 |
+
gr.Markdown("C:经常(过去一周内,有3-4天有过这类情况)")
|
38 |
+
gr.Markdown("D:总是如此(过去一周内,有5-7天有过类似情况)")
|
39 |
+
btn = gr.Button("继续")
|
40 |
+
with gr.Column(visible=False) as question:
|
41 |
+
r1 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "1.我感到心里沮丧,郁闷",type = "index")
|
42 |
+
r2 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "2.我感到早晨心情最好",type = "index")
|
43 |
+
r3 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "3.我要哭或想哭",type = "index")
|
44 |
+
r4 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "4.我夜间睡眠不好",type = "index")
|
45 |
+
r5 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "5.我吃饭像平常一样多",type = "index")
|
46 |
+
r6 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "6.我的性功能正常",type = "index")
|
47 |
+
r7 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "7.我感到体重减轻",type = "index")
|
48 |
+
r8 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "8.我为便秘烦恼",type = "index")
|
49 |
+
r9 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "9.我的心跳比平时快",type = "index")
|
50 |
+
r10 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "10.我无故感到疲劳",type = "index")
|
51 |
+
r11 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "11.我的头脑像往常一样清楚",type = "index")
|
52 |
+
r12 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "12.我做事情像平时一样不感到困难",type = "index")
|
53 |
+
r13 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "13.我坐卧不安,难以保持平静",type = "index")
|
54 |
+
r14 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "14.我对未来感到有希望",type = "index")
|
55 |
+
r15 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "15.我比平时更容易激怒",type = "index")
|
56 |
+
r16 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "16.我觉得决定什么事情很容易",type = "index")
|
57 |
+
r17 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "17.我感到自己是有用的和不可缺少的人",type = "index")
|
58 |
+
r18 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "18.我的生活很有意义",type = "index")
|
59 |
+
r19 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "19.假若我死了别人会过得更好",type = "index")
|
60 |
+
r20 = gr.Radio(["A.从无或偶尔","B.有时","C.经常","D.总是如此"],label = "20.我仍旧喜爱自己平时喜爱的东西",type = "index")
|
61 |
+
btn2 = gr.Button("提交")
|
62 |
+
with gr.Column(visible=False) as result:
|
63 |
+
score = gr.Textbox(label="得分")
|
64 |
+
exp = gr.Textbox(label="结果解释")
|
65 |
+
adv = gr.Textbox(label="指导建议")
|
66 |
+
#btn3 = gr.Button("更多")
|
67 |
+
btn.click(visibility,outputs=question)
|
68 |
+
btn2.click(Score,[r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20],[result,score,exp,adv])
|
69 |
+
|
70 |
+
btn2.click(Score,[r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20],[result,score,exp,adv])
|
71 |
+
|
test.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
from consult import consult
|
6 |
+
from scale import scale
|
7 |
+
|
8 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
|
9 |
+
|
10 |
+
score1 = 0 # 量表得分,全局可修改
|
11 |
+
|
12 |
+
with gr.Blocks() as test_mode:
|
13 |
+
# 量表得分
|
14 |
+
|
15 |
+
with gr.Tab("量表"):
|
16 |
+
scale.render()
|
17 |
+
with gr.Tab("咨询"):
|
18 |
+
consult.render()
|
19 |
+
with gr.Tab("综合评估与建议"):
|
20 |
+
gr.Markdown("结论页面")
|
user_data/data.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
username,date,time,scores,remark
|
2 |
+
lizhiyu,2024/2/21,21:23:15,1,�dz��ã�
|
3 |
+
userA,2024/2/21,21:23:15,2,һ���
|
4 |
+
test0,2024/2/22,13:22:21,2,OK
|
5 |
+
liusu,2024-02-22,15:32:05,2,OK
|
6 |
+
liusu,2024-02-22,15:34:48,50,����Ŭ��
|
user_login/login.csv
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
username,password
|
2 |
+
lizhiyu,123456
|
3 |
+
test,0
|
4 |
+
test0,3784848
|
5 |
+
liusu,123456
|