betterme
commited on
Commit
·
6b57b99
1
Parent(s):
0c62912
update
Browse files- pages/chatbase.py +51 -0
- pages/多轮对话.py +16 -9
- run.sh +1 -1
pages/chatbase.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
# @Project : AI. @by PyCharm
|
4 |
+
# @File : chatpdf
|
5 |
+
# @Time : 2023/4/25 17:01
|
6 |
+
# @Author : betterme
|
7 |
+
# @WeChat : meutils
|
8 |
+
# @Software : PyCharm
|
9 |
+
# @Description :
|
10 |
+
|
11 |
+
from meutils.pipe import *
|
12 |
+
from chatllm.applications import ChatBase
|
13 |
+
from chatllm.utils import llm_load4chat
|
14 |
+
|
15 |
+
import streamlit as st
|
16 |
+
from appzoo.streamlit_app.utils import display_pdf, reply4input
|
17 |
+
|
18 |
+
st.set_page_config('🔥ChatLLM', layout='centered', initial_sidebar_state='collapsed')
|
19 |
+
|
20 |
+
|
21 |
+
@st.experimental_singleton
|
22 |
+
def get_chat_func():
|
23 |
+
chat_func = llm_load4chat()
|
24 |
+
return chat_func
|
25 |
+
|
26 |
+
|
27 |
+
chat_func = get_chat_func()
|
28 |
+
|
29 |
+
qa = ChatBase(chat_func=chat_func)
|
30 |
+
|
31 |
+
|
32 |
+
def reply_func(query):
|
33 |
+
for response, _ in qa(query=query):
|
34 |
+
yield response
|
35 |
+
|
36 |
+
|
37 |
+
# def reply_func(x):
|
38 |
+
# for i in range(10):
|
39 |
+
# time.sleep(1)
|
40 |
+
# x += str(i)
|
41 |
+
# yield x
|
42 |
+
|
43 |
+
|
44 |
+
container = st.container() # 占位符
|
45 |
+
text = st.text_area(label="用户输入", height=100, placeholder="请在这儿输入您的问题")
|
46 |
+
# knowledge_base = st.sidebar.text_area(label="知识库", height=100, placeholder="请在这儿输入您的问题")
|
47 |
+
|
48 |
+
if st.button("发送", key="predict"):
|
49 |
+
with st.spinner("AI正在思考,请稍等........"):
|
50 |
+
history = st.session_state.get('state')
|
51 |
+
st.session_state["state"] = reply4input(text, history, container=container, reply_func=reply_func)
|
pages/多轮对话.py
CHANGED
@@ -6,25 +6,32 @@
|
|
6 |
# @Author : yuanjie
|
7 |
# @WeChat : meutils
|
8 |
# @Software : PyCharm
|
9 |
-
# @Description :
|
|
|
|
|
|
|
10 |
import streamlit as st
|
11 |
-
from
|
12 |
|
13 |
from appzoo.streamlit_app.utils import reply4input
|
14 |
|
15 |
if __name__ == '__main__':
|
16 |
-
def display_previous_message(texts=None):
|
17 |
-
if texts:
|
18 |
-
for msg in texts:
|
19 |
-
message(msg, avatar_style="bottts") # display all the previous message
|
20 |
-
|
21 |
|
22 |
-
|
23 |
|
24 |
container = st.container() # 占位符
|
25 |
text = st.text_area(label="用户输入", height=100, placeholder="请在这儿输入您的问题")
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
if st.button("发送", key="predict"):
|
28 |
with st.spinner("AI正在思考,请稍等........"):
|
29 |
history = st.session_state.get('state')
|
30 |
-
st.session_state["state"] = reply4input(text, history, container=container
|
|
|
|
6 |
# @Author : yuanjie
|
7 |
# @WeChat : meutils
|
8 |
# @Software : PyCharm
|
9 |
+
# @Description :
|
10 |
+
import time
|
11 |
+
import types
|
12 |
+
|
13 |
import streamlit as st
|
14 |
+
from meutils.pipe import *
|
15 |
|
16 |
from appzoo.streamlit_app.utils import reply4input
|
17 |
|
18 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
previous_messages = ["你好!我是你的电影小助手,很高兴为您服务。", "你可以向我提问。"]
|
21 |
|
22 |
container = st.container() # 占位符
|
23 |
text = st.text_area(label="用户输入", height=100, placeholder="请在这儿输入您的问题")
|
24 |
|
25 |
+
|
26 |
+
def reply_func(query):
|
27 |
+
for i in range(10):
|
28 |
+
time.sleep(0.5)
|
29 |
+
yield query
|
30 |
+
query += str(i)
|
31 |
+
|
32 |
+
|
33 |
if st.button("发送", key="predict"):
|
34 |
with st.spinner("AI正在思考,请稍等........"):
|
35 |
history = st.session_state.get('state')
|
36 |
+
st.session_state["state"] = reply4input(text, history, container=container, reply_func=reply_func,
|
37 |
+
previous_messages=previous_messages)
|
run.sh
CHANGED
@@ -6,5 +6,5 @@
|
|
6 |
# @Software : PyCharm
|
7 |
# @Description : ${DESCRIPTION}
|
8 |
|
9 |
-
streamlit run _👋_.py --server.port
|
10 |
|
|
|
6 |
# @Software : PyCharm
|
7 |
# @Description : ${DESCRIPTION}
|
8 |
|
9 |
+
streamlit run _👋_.py --server.port 7766
|
10 |
|