Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import uuid
|
3 |
+
import gradio as gr
|
4 |
+
from medisearch_client import MediSearchClient
|
5 |
+
|
6 |
+
def run_medisearch_chatbot(query, follow_up_query):
|
7 |
+
api_key = "gx4XXBhE7Zrga682gmEm"
|
8 |
+
conversation_id = str(uuid.uuid4())
|
9 |
+
client = MediSearchClient(api_key=api_key)
|
10 |
+
|
11 |
+
responses = client.send_user_message(conversation=[query],
|
12 |
+
conversation_id=conversation_id,
|
13 |
+
language="Chinese",
|
14 |
+
should_stream_response=False)
|
15 |
+
|
16 |
+
text_response = ""
|
17 |
+
for response in responses:
|
18 |
+
if response["event"] == "llm_response":
|
19 |
+
text_response = response["text"]
|
20 |
+
break
|
21 |
+
|
22 |
+
if follow_up_query:
|
23 |
+
responses = client.send_user_message(conversation=[query, text_response, follow_up_query],
|
24 |
+
conversation_id=conversation_id,
|
25 |
+
language="Chinese",
|
26 |
+
should_stream_response=False)
|
27 |
+
for response in responses:
|
28 |
+
if response["event"] == "llm_response":
|
29 |
+
text_response = response["text"]
|
30 |
+
break
|
31 |
+
|
32 |
+
return text_response
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=run_medisearch_chatbot,
|
35 |
+
inputs=[gr.inputs.Textbox(label="输入您的问题:"),
|
36 |
+
gr.inputs.Textbox(label="输入后续查询(可选):")],
|
37 |
+
outputs=gr.outputs.Textbox(label="回复:"),
|
38 |
+
title="<span style='font-style: italic; font-weight: bold; color: darkred;'>智悠科技聊天机器人</span> - 智能漂浮健康管家",
|
39 |
+
description="您正在和智悠科技的健康大语言模型进行对话,感谢您的使用!")
|
40 |
+
|
41 |
+
#iface.launch(share=True, debug=True)
|
42 |
+
iface.launch()
|