Spaces:
Build error
Build error
| import json | |
| import uuid | |
| import gradio as gr | |
| from medisearch_client import MediSearchClient | |
| def run_medisearch_chatbot(query, follow_up_query): | |
| api_key = "gx4XXBhE7Zrga682gmEm" | |
| conversation_id = str(uuid.uuid4()) | |
| client = MediSearchClient(api_key=api_key) | |
| responses = client.send_user_message(conversation=[query], | |
| conversation_id=conversation_id, | |
| language="Chinese", | |
| should_stream_response=False) | |
| text_response = "" | |
| for response in responses: | |
| if response["event"] == "llm_response": | |
| text_response = response["text"] | |
| break | |
| if follow_up_query: | |
| responses = client.send_user_message(conversation=[query, text_response, follow_up_query], | |
| conversation_id=conversation_id, | |
| language="Chinese", | |
| should_stream_response=False) | |
| for response in responses: | |
| if response["event"] == "llm_response": | |
| text_response = response["text"] | |
| break | |
| return text_response | |
| iface = gr.Interface(fn=run_medisearch_chatbot, | |
| inputs=[gr.inputs.Textbox(label="输入您的问题:"), | |
| gr.inputs.Textbox(label="输入后续查询(可选):")], | |
| outputs=gr.outputs.Textbox(label="回复:"), | |
| title="<span style='font-style: italic; font-weight: bold; color: darkred;'>模多多AI聊天机器人</span> - PlentyOfModels健康管家", | |
| description="您正在和模多多的健康大语言模型进行对话,感谢您的使用!") | |
| #iface.launch(share=True, debug=True) | |
| iface.launch() |