Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
os.environ["no_proxy"] = "localhost,127.0.0.1,::1" | |
def advice1(radio1, radio2, radio3): | |
# 有关睡眠问题的建议 | |
if radio1 == 0: | |
if radio2 == "存在": | |
return "嗜睡" | |
else: | |
return radio2 | |
if radio1 == 1: | |
return radio3 | |
def advice2(radio4): | |
# 有关饮食问题的建议 | |
if radio4 == 0: | |
return "不存在" | |
if radio4 == 1: | |
return "增重" | |
else: | |
return "消瘦" | |
def advice3(radio5, radio6): | |
# 有关情绪问题的建议 | |
if radio5 == "好": | |
return "不存在情绪问题" | |
if radio5 == "不好": | |
return "抑郁情绪持续了" + radio6 | |
def advice4(radio5, text3_1, radio8, radio9, radio10): | |
# 有关自杀倾向的建议 | |
if radio5 == "不好": | |
if keyword(text3_1): | |
if radio8 == 0: | |
if radio9 == 0: | |
if radio10 == "没想过": | |
return ",有自杀倾向" | |
if radio10 == "想过,没想过具体时间和地点": | |
return ",自杀倾向较严重" | |
if radio10 == "想过具体做法,时间和地点,没实践过": | |
return ",自杀倾向严重" | |
if radio10 == "实践过": | |
return ",有过自杀行为" | |
else: | |
return ",有自杀倾向" | |
else: | |
return "" | |
else: | |
return "" | |
def advice( | |
radio1, radio2, radio3, radio4, radio5, radio6, text3_1, radio8, radio9, radio10,result1,result2,result3 | |
): | |
symptoms = "" | |
if advice1(radio1, radio2, radio3) == "不存在" and advice2(radio4) == "不存在": | |
symptoms = "不存在睡眠、饮食问题且" | |
if advice1(radio1, radio2, radio3) != "不存在" and advice2(radio4) == "不存在": | |
symptoms = "存在" + advice1(radio1, radio2, radio3) + "问题,不存在饮食问题且" | |
if advice1(radio1, radio2, radio3) == "不存在" and advice2(radio4) != "不存在": | |
symptoms = "不存在睡眠问题,存在" + advice2(radio4) + "问题且" | |
final_score=result1+result2+result3 | |
print("最终得分:",final_score) | |
return ( | |
gr.Column(visible=True), | |
gr.Markdown(visible=True), | |
final_score, | |
gr.Textbox( | |
value="你" | |
+ symptoms | |
+ advice3(radio5, radio6) | |
+ advice4(radio5, text3_1, radio8, radio9, radio10) | |
+ "。\n 抑郁症症状因人而异,并不应当只以是否存在上述症状来判断,并且可能存在上述症状以外更个人化的症状,如果存在强烈的各种不适或者怀疑自己有抑郁症,建议及时去进行专业检查和干预治疗,也有可能存在抑郁症以外的各类精神障碍与心理疾病,如焦虑症或双相情感障碍等等。\n 抑郁症和其他各类精神上的疾病不是患者的问题或者错误,也不是矫情或者敏感,也不说明患者与其他人有什么不同,他们只是生病了,需要进行治疗而已。此外,一次测试结果不能代表全部,我们希望你能持续地关注自己的心理健康状态,常来这里自测评估一下。最后,不管你有没有抑郁症或者其他疾病,都拍拍你,抱抱你,祝愿你接下来的生活光明灿烂!", | |
visible=True, | |
), | |
) | |
def final_advice( | |
radio1, radio2, radio3, radio4, radio5, radio6, text3_1, radio8, radio9, radio10 | |
): | |
return gr.Textbox( | |
visible=True, | |
value=advice( | |
radio1, | |
radio2, | |
radio3, | |
radio4, | |
radio5, | |
radio6, | |
text3_1, | |
radio8, | |
radio9, | |
radio10, | |
), | |
) | |
def visibility(): # 让下一部分出现 | |
return gr.Column(visible=True) | |
def visibility2(): # 让下一道选择题出现 | |
return gr.Radio(visible=True) | |
def visibility3(): # 针对有标题切换的情况 | |
return ( | |
gr.Markdown(visible=True), | |
gr.Radio(visible=True), | |
) | |
def visibility4(): | |
return gr.Markdown(visible=True) | |
def visibility_choice(choice): # 根据选择选项的不同决定下一道题是哪个 | |
if choice == 0: | |
return gr.Column(visible=True), gr.Column(visible=False) | |
else: | |
return gr.Column(visible=False), gr.Column(visible=True) | |
def visibility_choice2(choice): # 选择视频,语音还是文本输入 | |
if choice == 0: | |
return ( | |
gr.Column(visible=True), | |
gr.Column(visible=False), | |
gr.Column(visible=False), | |
) | |
if choice == 1: | |
return ( | |
gr.Column(visible=False), | |
gr.Column(visible=True), | |
gr.Column(visible=False), | |
) | |
else: | |
return ( | |
gr.Column(visible=False), | |
gr.Column(visible=False), | |
gr.Column(visible=True), | |
) | |
def visibility_choice3(choice): # 根据选择选项的不同决定下一道题是哪个 | |
if choice == "不好": | |
return ( | |
gr.Radio(visible=True), | |
gr.Column(visible=False), | |
gr.Column(visible=False), | |
) | |
else: | |
return ( | |
gr.Radio(visible=False), | |
gr.Column(visible=False), | |
gr.Column(visible=True), | |
) | |
def visibility_choice4(choice): # 根据选择选项的不同决定下一道题是哪个 | |
if choice == 0: | |
return gr.Radio(visible=True), gr.Radio(visible=False) | |
else: | |
return gr.Radio(visible=False), gr.Radio(visible=True) | |
def keyword( | |
text, | |
): # 设置关于自杀倾向问题的触发词(你决定要不要加一个文本负向概率大于一定值的判定) | |
keywords = ["轻生", "自杀", "死", "活着", "意义", "意思", "干劲"] | |
for i in range(len(keywords)): | |
if keywords[i].find(text) != -1: | |
return True | |
return False | |
def visibility_choice5(text): # 关于自杀倾向问题是否触发 | |
if keyword(text) is True: | |
return gr.Radio(visible=True), gr.Column(visible=False) | |
else: | |
return gr.Radio(visible=False), gr.Column(visible=True) | |