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("Look at me...") #text_button.click(flip_text, inputs=text_input, outputs=text_output) #image_button.click(flip_image, inputs=image_input, outputs=image_output) demo.launch()