Liusuthu's picture
upload main part
7950af4 verified
raw
history blame
3.86 kB
import os
import gradio as gr
os.environ["no_proxy"] = "localhost,127.0.0.1,::1"
# from paddlenlp import Taskflow
def visibility(choice):
if choice == "不好":
return gr.Column(visible=True), gr.Radio(visible=False)
else:
return gr.Column(visible=False), gr.Radio(visible=True)
def visibility2():
return gr.Radio(visible=True)
def visibility3(choice):
if choice == "不好":
return gr.Column(visible=True), gr.Column(visible=False)
else:
return gr.Column(visible=False), gr.Column(visible=True)
def visibility4():
return gr.Column(visible=True)
def visibility5(choice):
if choice == "不好":
return (
gr.Column(visible=True),
gr.Column(visible=False),
gr.Column(visible=False),
)
else:
return (
gr.Column(visible=False),
gr.Column(visible=False),
gr.Column(visible=True),
)
def advice(ans1, ans2, ans3, ans4, ans5, ans6):
return gr.Textbox(visible=True, value="结束~")
with gr.Blocks() as chat:
gr.Markdown("让我们来聊聊天吧~")
with gr.Column():
radio1 = gr.Radio(["好", "不好"], label="你最近睡眠还好吗?")
with gr.Column(visible=False) as q1:
ans1 = gr.Textbox(
label="你入睡的时间一般在几点?一直持续地睡到几点醒来?醒来后是否还能入睡?"
)
with gr.Accordion(label="示例"):
gr.Markdown(
"我睡眠还好/我最近睡眠不太好,有点失眠/我最近睡眠不好,容易早醒"
)
btn1 = gr.Button("继续")
radio2 = gr.Radio(["好", "不好"], label="你最近食欲还好吗?", visible=False)
with gr.Column(visible=False) as q2:
ans2 = gr.Textbox(label="你体重上有什么变化吗?比如说增重或消瘦?")
with gr.Accordion(label="示例"):
gr.Markdown("")
btn2 = gr.Button("继续")
radio3 = gr.Radio(["好", "不好"], label="你最近心情还好吗?", visible=False)
with gr.Column(visible=False) as q3:
ans3 = gr.Textbox(label="你心情不好持续了多长时间呢?有在两周以上吗?")
with gr.Accordion(label="示例"):
gr.Markdown("")
btn3 = gr.Button("继续")
with gr.Column(visible=False) as q4:
ans4 = gr.Textbox(
label="你这段时间真的很不容易,愿意和我说说吗?说什么都可以,也许倾诉出来会好一些呢"
)
btn4 = gr.Button("抱抱你")
with gr.Column(visible=False) as q5:
ans5 = gr.Textbox(
label="你有什么兴趣爱好吗?平常都喜欢干什么事情呢?愿意和我说说吗?"
)
btn5 = gr.Button("继续")
with gr.Column(visible=False) as q6:
ans6 = gr.Textbox(
label="5.你愿意和我聊聊你最近都喜欢干些什么,或者有什么事情让你很沉浸,感到开心或者觉得很有意义吗?还有那些让你觉得自己很厉害,很有成就感的事情,比如说你做成了什么有难度的事情或者帮助了谁?什么都可以哦"
)
btn6 = gr.Button("提交")
adv = gr.Textbox(visible=False)
radio1.change(visibility, radio1, [q1, radio2])
btn1.click(visibility2, outputs=radio2)
radio2.change(visibility, radio2, [q2, radio3])
btn2.click(visibility2, outputs=radio3)
radio3.change(visibility5, radio3, [q3, q4, q5])
btn3.click(visibility4, outputs=q4)
btn4.click(visibility4, outputs=q5)
btn5.click(visibility4, outputs=q6)
btn6.click(advice, [ans1, ans2, ans3, ans4, ans5, ans6], adv)