File size: 2,858 Bytes
df182ba 1c579df df182ba 3f10a03 958fa67 df182ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | import numpy as np
import gradio as gr
import random
import time
from updated_predict import working_func
theme = gr.themes.Soft(
primary_hue="emerald",
secondary_hue="teal",
neutral_hue="indigo",
# text_size="text_lg",
# radius_size="radius_lg",
).set(
#body_background_fill='*checkbox_label_background_fill',
#body_background_fill='*block_title_background_fill',
body_background_fill='*background_fill_secondary',
background_fill_primary='*neutral_200',
block_background_fill='*table_even_background_fill',
button_border_width='*block_title_border_width',
button_shadow='*button_shadow_hover'
)
def flip_text(x):
return x[::-1]
def flip_image(x):
return np.fliplr(x)
def diagnosed_huxi():
return "呼吸科"
def diagnosed_shennei():
return "神经内科"
def diagnosed_xiaohua():
return "内科 消化科/胃肠科"
def diagnosed_xinnei():
return "内科 心脏内科"
text_output = gr.Textbox(label="科室")
with gr.Blocks(theme=theme) as demo:
gr.Markdown("医疗分诊助手")
gr.Image("bar.png")
with gr.Tab("常见疑问"):
with gr.Row():
btn1 = gr.Button(value="癫痫")
btn1.click(diagnosed_shennei, inputs=[], outputs=[text_output])
btn2 = gr.Button(value="咳嗽")
btn2.click(diagnosed_huxi, inputs=[], outputs=[text_output])
btn3 = gr.Button(value="感冒")
btn3.click(diagnosed_huxi, inputs=[], outputs=[text_output])
with gr.Row():
btn4 = gr.Button(value="高血压")
btn4.click(diagnosed_xinnei, inputs=[], outputs=[text_output])
btn5 = gr.Button(value="发烧")
btn5.click(diagnosed_huxi, inputs=[], outputs=[text_output])
btn6 = gr.Button(value="胃炎")
btn6.click(diagnosed_xiaohua, inputs=[], outputs=[text_output])
with gr.Row():
text_output.render()
with gr.Tab("手动键入"):
chatbot = gr.Chatbot()
msg = gr.Textbox(label="请输入症状或问题")
clear = gr.ClearButton([msg, chatbot])
def respond(message, chat_history):
result = working_func(message)
bot_message = "科室:" + result[0] + ',' + result[1] + '\n' + "回答:" + result[2]
chat_history.append((message, bot_message))
time.sleep(2)
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
#with gr.Accordion("本产品只提供分诊辅助,一切以医生诊断为主。"):
gr.Markdown("本产品只提供分诊辅助,一切以医生诊断为主。")
#text_button.click(flip_text, inputs=text_input, outputs=text_output)
#image_button.click(flip_image, inputs=image_input, outputs=image_output)
demo.launch()
|