Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
from dotenv import load_dotenv
|
3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
4 |
-
from langchain.embeddings import OpenAIEmbeddings
|
5 |
from langchain.vectorstores import FAISS
|
6 |
from langchain.chat_models import ChatOpenAI
|
7 |
from langchain.memory import ConversationBufferMemory
|
@@ -10,6 +10,11 @@ from langchain.document_loaders import PyPDFLoader, TextLoader, JSONLoader, CSVL
|
|
10 |
import tempfile
|
11 |
import os
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def get_pdf_text(pdf_docs):
|
15 |
temp_dir = tempfile.TemporaryDirectory()
|
@@ -20,25 +25,21 @@ def get_pdf_text(pdf_docs):
|
|
20 |
pdf_doc = pdf_loader.load()
|
21 |
return pdf_doc
|
22 |
|
23 |
-
|
24 |
def get_text_file(docs):
|
25 |
text_loader = TextLoader(docs.name)
|
26 |
text = text_loader.load()
|
27 |
return [text]
|
28 |
|
29 |
-
|
30 |
def get_csv_file(docs):
|
31 |
csv_loader = CSVLoader(docs.name)
|
32 |
csv_text = csv_loader.load()
|
33 |
return csv_text.values.tolist()
|
34 |
|
35 |
-
|
36 |
def get_json_file(docs):
|
37 |
json_loader = JSONLoader(docs.name)
|
38 |
json_text = json_loader.load()
|
39 |
return [json_text]
|
40 |
|
41 |
-
|
42 |
def get_text_chunks(documents):
|
43 |
text_splitter = RecursiveCharacterTextSplitter(
|
44 |
chunk_size=1000,
|
@@ -49,13 +50,11 @@ def get_text_chunks(documents):
|
|
49 |
documents = text_splitter.split_documents(documents)
|
50 |
return documents
|
51 |
|
52 |
-
|
53 |
def get_vectorstore(text_chunks):
|
54 |
embeddings = OpenAIEmbeddings()
|
55 |
vectorstore = FAISS.from_documents(text_chunks, embeddings)
|
56 |
return vectorstore
|
57 |
|
58 |
-
|
59 |
def get_conversation_chain(vectorstore):
|
60 |
gpt_model_name = 'gpt-3.5-turbo'
|
61 |
llm = ChatOpenAI(model_name=gpt_model_name)
|
@@ -69,7 +68,6 @@ def get_conversation_chain(vectorstore):
|
|
69 |
)
|
70 |
return conversation_chain
|
71 |
|
72 |
-
|
73 |
def handle_userinput(user_question):
|
74 |
response = st.session_state.conversation({'question': user_question})
|
75 |
st.session_state.chat_history = response['chat_history']
|
@@ -82,7 +80,6 @@ def handle_userinput(user_question):
|
|
82 |
st.write(bot_template.replace(
|
83 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
84 |
|
85 |
-
|
86 |
def main():
|
87 |
load_dotenv()
|
88 |
st.set_page_config(page_title="Chat with multiple Files",
|
@@ -126,6 +123,6 @@ def main():
|
|
126 |
st.session_state.conversation = get_conversation_chain(
|
127 |
vectorstore)
|
128 |
|
129 |
-
|
130 |
if __name__ == '__main__':
|
131 |
main()
|
|
|
|
1 |
import streamlit as st
|
2 |
from dotenv import load_dotenv
|
3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
4 |
+
from langchain.embeddings import OpenAIEmbeddings
|
5 |
from langchain.vectorstores import FAISS
|
6 |
from langchain.chat_models import ChatOpenAI
|
7 |
from langchain.memory import ConversationBufferMemory
|
|
|
10 |
import tempfile
|
11 |
import os
|
12 |
|
13 |
+
css = """
|
14 |
+
<style>
|
15 |
+
/* 여기에 CSS 코드를 넣어주세요 */
|
16 |
+
</style>
|
17 |
+
"""
|
18 |
|
19 |
def get_pdf_text(pdf_docs):
|
20 |
temp_dir = tempfile.TemporaryDirectory()
|
|
|
25 |
pdf_doc = pdf_loader.load()
|
26 |
return pdf_doc
|
27 |
|
|
|
28 |
def get_text_file(docs):
|
29 |
text_loader = TextLoader(docs.name)
|
30 |
text = text_loader.load()
|
31 |
return [text]
|
32 |
|
|
|
33 |
def get_csv_file(docs):
|
34 |
csv_loader = CSVLoader(docs.name)
|
35 |
csv_text = csv_loader.load()
|
36 |
return csv_text.values.tolist()
|
37 |
|
|
|
38 |
def get_json_file(docs):
|
39 |
json_loader = JSONLoader(docs.name)
|
40 |
json_text = json_loader.load()
|
41 |
return [json_text]
|
42 |
|
|
|
43 |
def get_text_chunks(documents):
|
44 |
text_splitter = RecursiveCharacterTextSplitter(
|
45 |
chunk_size=1000,
|
|
|
50 |
documents = text_splitter.split_documents(documents)
|
51 |
return documents
|
52 |
|
|
|
53 |
def get_vectorstore(text_chunks):
|
54 |
embeddings = OpenAIEmbeddings()
|
55 |
vectorstore = FAISS.from_documents(text_chunks, embeddings)
|
56 |
return vectorstore
|
57 |
|
|
|
58 |
def get_conversation_chain(vectorstore):
|
59 |
gpt_model_name = 'gpt-3.5-turbo'
|
60 |
llm = ChatOpenAI(model_name=gpt_model_name)
|
|
|
68 |
)
|
69 |
return conversation_chain
|
70 |
|
|
|
71 |
def handle_userinput(user_question):
|
72 |
response = st.session_state.conversation({'question': user_question})
|
73 |
st.session_state.chat_history = response['chat_history']
|
|
|
80 |
st.write(bot_template.replace(
|
81 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
82 |
|
|
|
83 |
def main():
|
84 |
load_dotenv()
|
85 |
st.set_page_config(page_title="Chat with multiple Files",
|
|
|
123 |
st.session_state.conversation = get_conversation_chain(
|
124 |
vectorstore)
|
125 |
|
|
|
126 |
if __name__ == '__main__':
|
127 |
main()
|
128 |
+
|