Spaces:
Sleeping
Sleeping
Vinh Nguyen
commited on
Commit
β’
b5bc349
1
Parent(s):
7713f97
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import tempfile
|
3 |
|
4 |
import streamlit as st
|
|
|
5 |
|
6 |
from langchain.callbacks.base import BaseCallbackHandler
|
7 |
from langchain.chains import ConversationalRetrievalChain
|
@@ -20,10 +21,26 @@ from streamlit_extras.add_vertical_space import add_vertical_space
|
|
20 |
# TODO: hide side bar
|
21 |
# TODO: make the page attactive
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
st.write("**Chat** with Documents")
|
28 |
|
29 |
# Setup memory for contextual conversation
|
@@ -47,7 +64,7 @@ def configure_retriever(uploaded_files):
|
|
47 |
splits = text_splitter.split_documents(docs)
|
48 |
|
49 |
# Create embeddings and store in vectordb
|
50 |
-
embeddings = HuggingFaceEmbeddings(model_name=
|
51 |
vectordb = DocArrayInMemorySearch.from_documents(splits, embeddings)
|
52 |
|
53 |
# Define retriever
|
@@ -119,7 +136,7 @@ if uploaded_files:
|
|
119 |
|
120 |
# Setup LLM and QA chain
|
121 |
llm = ChatOpenAI(
|
122 |
-
model_name=
|
123 |
openai_api_key=openai_api_key,
|
124 |
temperature=0,
|
125 |
streaming=True,
|
@@ -129,7 +146,11 @@ if uploaded_files:
|
|
129 |
llm, retriever=retriever, memory=memory, verbose=False
|
130 |
)
|
131 |
|
132 |
-
avatars = {
|
|
|
|
|
|
|
|
|
133 |
for msg in msgs.messages:
|
134 |
st.chat_message(avatars[msg.type]).write(msg.content)
|
135 |
|
|
|
2 |
import tempfile
|
3 |
|
4 |
import streamlit as st
|
5 |
+
from chat_profile import ChatProfileRoleEnum
|
6 |
|
7 |
from langchain.callbacks.base import BaseCallbackHandler
|
8 |
from langchain.chains import ConversationalRetrievalChain
|
|
|
21 |
# TODO: hide side bar
|
22 |
# TODO: make the page attactive
|
23 |
|
24 |
+
# configs
|
25 |
+
LLM_MODEL_NAME = "gpt-3.5-turbo"
|
26 |
+
EMBEDDING_MODEL_NAME = "all-MiniLM-L6-v2"
|
27 |
+
|
28 |
+
st.set_page_config(
|
29 |
+
page_title=":books: InkChatGPT: Chat with Documents",
|
30 |
+
page_icon="π",
|
31 |
+
initial_sidebar_state="collapsed",
|
32 |
+
menu_items={
|
33 |
+
"Get Help": "https://x.com/vinhnx",
|
34 |
+
"Report a bug": "https://github.com/vinhnx/InkChatGPT/issues",
|
35 |
+
"About": "InkChatGPT is a Streamlit application that allows users to upload PDF documents and engage in a conversational Q&A with a language model (LLM) based on the content of those documents.",
|
36 |
+
},
|
37 |
+
)
|
38 |
+
|
39 |
+
st.image("./assets/icon.jpg", width=100)
|
40 |
+
st.header(
|
41 |
+
":gray[:books: InkChatGPT]",
|
42 |
+
divider="blue",
|
43 |
+
)
|
44 |
st.write("**Chat** with Documents")
|
45 |
|
46 |
# Setup memory for contextual conversation
|
|
|
64 |
splits = text_splitter.split_documents(docs)
|
65 |
|
66 |
# Create embeddings and store in vectordb
|
67 |
+
embeddings = HuggingFaceEmbeddings(model_name=EMBEDDING_MODEL_NAME)
|
68 |
vectordb = DocArrayInMemorySearch.from_documents(splits, embeddings)
|
69 |
|
70 |
# Define retriever
|
|
|
136 |
|
137 |
# Setup LLM and QA chain
|
138 |
llm = ChatOpenAI(
|
139 |
+
model_name=LLM_MODEL_NAME,
|
140 |
openai_api_key=openai_api_key,
|
141 |
temperature=0,
|
142 |
streaming=True,
|
|
|
146 |
llm, retriever=retriever, memory=memory, verbose=False
|
147 |
)
|
148 |
|
149 |
+
avatars = {
|
150 |
+
ChatProfileRoleEnum.Human: "user",
|
151 |
+
ChatProfileRoleEnum.AI: "assistant",
|
152 |
+
}
|
153 |
+
|
154 |
for msg in msgs.messages:
|
155 |
st.chat_message(avatars[msg.type]).write(msg.content)
|
156 |
|