Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,12 +9,12 @@ from langchain.vectorstores import FAISS
|
|
| 9 |
from langchain.chains import RetrievalQA
|
| 10 |
from langchain.chat_models import ChatOpenAI
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
|
| 20 |
def initialize_aliyun_qa_bot(vector_store_dir: str="aliyun_qa"):
|
|
@@ -36,7 +36,7 @@ def aliyun_chat(message, history):
|
|
| 36 |
print(f"[message]{message}")
|
| 37 |
print(f"[history]{history}")
|
| 38 |
# TODO: 从命令行参数中获取
|
| 39 |
-
|
| 40 |
|
| 41 |
ans = ALIYUN_BOT({"query": message})
|
| 42 |
# 如果检索出结果,或者开了大模型聊天模式
|
|
@@ -44,14 +44,15 @@ def aliyun_chat(message, history):
|
|
| 44 |
if ans["source_documents"] or enable_chat:
|
| 45 |
print(f"[result]{ans['result']}")
|
| 46 |
print(f"[source_documents]{ans['source_documents']}")
|
| 47 |
-
return ans["result"]
|
| 48 |
# 否则输出套路话术
|
| 49 |
else:
|
| 50 |
return "基于现有文档数据,无法回答你的问题,请您联系对应的阿里云企业咨询顾问。"
|
| 51 |
|
| 52 |
|
| 53 |
def launch_gradio():
|
| 54 |
-
|
|
|
|
| 55 |
fn=aliyun_chat,
|
| 56 |
title="企业数字化转型咨询顾问(aliyun)问答机器人",
|
| 57 |
examples=["阿里云有没有成熟的方法或者模板能够供我们去把业务价值和底座组件对应起来?","我们要建设中交二航局的数字化底座,阿里云有什么建议","公共云上,EMR和MaxCompute的使用量多少?","阿里公共云上能用maxcompute吗?"],
|
|
@@ -63,6 +64,11 @@ def launch_gradio():
|
|
| 63 |
chatbot=gr.Chatbot(height=450),
|
| 64 |
)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
demo.launch(auth=("admin", "leanvalue"))
|
| 67 |
demo.deploy()
|
| 68 |
|
|
|
|
| 9 |
from langchain.chains import RetrievalQA
|
| 10 |
from langchain.chat_models import ChatOpenAI
|
| 11 |
|
| 12 |
+
enable_chat = False # 初始化为False
|
| 13 |
|
| 14 |
+
def toggle_enable_chat():
|
| 15 |
+
global enable_chat
|
| 16 |
+
enable_chat = not enable_chat
|
| 17 |
+
return f"Enable Chat set to {enable_chat}"
|
| 18 |
|
| 19 |
|
| 20 |
def initialize_aliyun_qa_bot(vector_store_dir: str="aliyun_qa"):
|
|
|
|
| 36 |
print(f"[message]{message}")
|
| 37 |
print(f"[history]{history}")
|
| 38 |
# TODO: 从命令行参数中获取
|
| 39 |
+
global enable_chat
|
| 40 |
|
| 41 |
ans = ALIYUN_BOT({"query": message})
|
| 42 |
# 如果检索出结果,或者开了大模型聊天模式
|
|
|
|
| 44 |
if ans["source_documents"] or enable_chat:
|
| 45 |
print(f"[result]{ans['result']}")
|
| 46 |
print(f"[source_documents]{ans['source_documents']}")
|
| 47 |
+
return ans["result"]
|
| 48 |
# 否则输出套路话术
|
| 49 |
else:
|
| 50 |
return "基于现有文档数据,无法回答你的问题,请您联系对应的阿里云企业咨询顾问。"
|
| 51 |
|
| 52 |
|
| 53 |
def launch_gradio():
|
| 54 |
+
# 创建 ChatInterface 和其他组件
|
| 55 |
+
chat_interface = gr.ChatInterface(
|
| 56 |
fn=aliyun_chat,
|
| 57 |
title="企业数字化转型咨询顾问(aliyun)问答机器人",
|
| 58 |
examples=["阿里云有没有成熟的方法或者模板能够供我们去把业务价值和底座组件对应起来?","我们要建设中交二航局的数字化底座,阿里云有什么建议","公共云上,EMR和MaxCompute的使用量多少?","阿里公共云上能用maxcompute吗?"],
|
|
|
|
| 64 |
chatbot=gr.Chatbot(height=450),
|
| 65 |
)
|
| 66 |
|
| 67 |
+
toggle_chat_button = gr.Button(value="Toggle Chat", fn=toggle_enable_chat)
|
| 68 |
+
|
| 69 |
+
demo = gr.TabbedInterface([chat_interface, toggle_chat_button],
|
| 70 |
+
["Chat", "Settings"])
|
| 71 |
+
|
| 72 |
demo.launch(auth=("admin", "leanvalue"))
|
| 73 |
demo.deploy()
|
| 74 |
|