Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from dotenv import load_dotenv
|
3 |
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
@@ -11,11 +219,6 @@ import json
|
|
11 |
from pathlib import Path
|
12 |
from pprint import pprint
|
13 |
|
14 |
-
from langchain.document_loaders import PyPDFLoader, TextLoader, JSONLoader, CSVLoader
|
15 |
-
import tempfile # μμ νμΌμ μμ±νκΈ° μν λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
16 |
-
import os
|
17 |
-
from huggingface_hub import hf_hub_download # Hugging Face Hubμμ λͺ¨λΈμ λ€μ΄λ‘λνκΈ° μν ν¨μμ
λλ€.
|
18 |
-
|
19 |
# PDF λ¬Έμλ‘λΆν° ν
μ€νΈλ₯Ό μΆμΆνλ ν¨μμ
λλ€.
|
20 |
def get_pdf_text(pdf_docs):
|
21 |
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
@@ -26,9 +229,6 @@ def get_pdf_text(pdf_docs):
|
|
26 |
pdf_doc = pdf_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
27 |
return pdf_doc # μΆμΆν ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
28 |
|
29 |
-
# κ³Όμ
|
30 |
-
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
31 |
-
|
32 |
def get_text_file(text_docs):
|
33 |
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
34 |
temp_filepath = os.path.join(temp_dir.name, text_docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
@@ -62,21 +262,6 @@ def get_json_file(json_docs):
|
|
62 |
json_doc = json_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
63 |
return json_doc # μΆμΆλ ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
# def get_text_file(text_docs):
|
69 |
-
#
|
70 |
-
# pass
|
71 |
-
#
|
72 |
-
# def get_csv_file(csv_docs):
|
73 |
-
# pass
|
74 |
-
#
|
75 |
-
# def get_json_file(json_docs):
|
76 |
-
#
|
77 |
-
#
|
78 |
-
# pass
|
79 |
-
|
80 |
|
81 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
82 |
def get_text_chunks(documents):
|
@@ -105,7 +290,7 @@ def get_conversation_chain(vectorstore):
|
|
105 |
model_path = hf_hub_download(repo_id=model_name_or_path, filename=model_basename)
|
106 |
|
107 |
llm = LlamaCpp(model_path=model_path,
|
108 |
-
n_ctx=
|
109 |
input={"temperature": 0.75, "max_length": 2000, "top_p": 1},
|
110 |
verbose=True, )
|
111 |
# λν κΈ°λ‘μ μ μ₯νκΈ° μν λ©λͺ¨λ¦¬λ₯Ό μμ±ν©λλ€.
|
@@ -134,12 +319,6 @@ def handle_userinput(user_question):
|
|
134 |
else:
|
135 |
st.write(bot_template.replace(
|
136 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
137 |
-
text_chunks = []
|
138 |
-
def initialize_conversation_chain():
|
139 |
-
# Add the necessary code to initialize the conversation_chain
|
140 |
-
# This may include loading the LlamaCpp model and creating the conversation_chain
|
141 |
-
vectorstore = get_vectorstore(text_chunks) # Replace this with the appropriate code
|
142 |
-
return get_conversation_chain(vectorstore)
|
143 |
|
144 |
|
145 |
def main():
|
@@ -148,24 +327,14 @@ def main():
|
|
148 |
page_icon=":books:")
|
149 |
st.write(css, unsafe_allow_html=True)
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
st.session_state.
|
155 |
-
# if "conversation" not in st.session_state:
|
156 |
-
# st.session_state.conversation = None
|
157 |
-
# if "chat_history" not in st.session_state:
|
158 |
-
# st.session_state.chat_history = None
|
159 |
|
160 |
st.header("Chat with multiple Files:")
|
161 |
user_question = st.text_input("Ask a question about your documents:")
|
162 |
-
# if user_question:
|
163 |
-
# handle_userinput(user_question)
|
164 |
if user_question:
|
165 |
-
# Ensure that conversation_chain is initialized before calling handle_userinput
|
166 |
-
if st.session_state.conversation is None:
|
167 |
-
st.session_state.conversation = initialize_conversation_chain()
|
168 |
-
|
169 |
handle_userinput(user_question)
|
170 |
|
171 |
with st.sidebar:
|
@@ -204,4 +373,4 @@ def main():
|
|
204 |
|
205 |
|
206 |
if __name__ == '__main__':
|
207 |
-
main()
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
# from dotenv import load_dotenv
|
3 |
+
# from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
4 |
+
# from langchain.vectorstores import FAISS
|
5 |
+
# from langchain.embeddings import HuggingFaceEmbeddings # General embeddings from HuggingFace models.
|
6 |
+
# from langchain.memory import ConversationBufferMemory
|
7 |
+
# from langchain.chains import ConversationalRetrievalChain
|
8 |
+
# from htmlTemplates import css, bot_template, user_template
|
9 |
+
# from langchain.llms import LlamaCpp
|
10 |
+
# import json
|
11 |
+
# from pathlib import Path
|
12 |
+
# from pprint import pprint
|
13 |
+
|
14 |
+
# from langchain.document_loaders import PyPDFLoader, TextLoader, JSONLoader, CSVLoader
|
15 |
+
# import tempfile # μμ νμΌμ μμ±νκΈ° μν λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
16 |
+
# import os
|
17 |
+
# from huggingface_hub import hf_hub_download # Hugging Face Hubμμ λͺ¨λΈμ λ€μ΄λ‘λνκΈ° μν ν¨μμ
λλ€.
|
18 |
+
|
19 |
+
# # PDF λ¬Έμλ‘λΆν° ν
μ€νΈλ₯Ό μΆμΆνλ ν¨μμ
λλ€.
|
20 |
+
# def get_pdf_text(pdf_docs):
|
21 |
+
# temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
22 |
+
# temp_filepath = os.path.join(temp_dir.name, pdf_docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
23 |
+
# with open(temp_filepath, "wb") as f: # μμ νμΌμ λ°μ΄λ리 μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
24 |
+
# f.write(pdf_docs.getvalue()) # PDF λ¬Έμμ λ΄μ©μ μμ νμΌμ μλλ€.
|
25 |
+
# pdf_loader = PyPDFLoader(temp_filepath) # PyPDFLoaderλ₯Ό μ¬μ©ν΄ PDFλ₯Ό λ‘λν©λλ€.
|
26 |
+
# pdf_doc = pdf_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
27 |
+
# return pdf_doc # μΆμΆν ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
28 |
+
|
29 |
+
# # κ³Όμ
|
30 |
+
# # μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
31 |
+
|
32 |
+
# def get_text_file(text_docs):
|
33 |
+
# temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
34 |
+
# temp_filepath = os.path.join(temp_dir.name, text_docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
35 |
+
|
36 |
+
# with open(temp_filepath, "wb") as f: # μμ νμΌμ ν
μ€νΈ μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
37 |
+
# f.write(text_docs.getvalue()) # ν
μ€νΈ λ¬Έμμ λ΄μ©μ μμ νμΌμ μλλ€.
|
38 |
+
|
39 |
+
# text_loader = TextLoader(temp_filepath) # TextLoaderλ₯Ό μ¬μ©ν΄ ν
μ€νΈ λ¬Έμλ₯Ό λ‘λν©λλ€.
|
40 |
+
# text_doc = text_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
41 |
+
# return text_doc # μΆμΆλ ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
42 |
+
|
43 |
+
# def get_csv_file(csv_docs):
|
44 |
+
# temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
45 |
+
# temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
46 |
+
|
47 |
+
# with open(temp_filepath, "wb") as f: # μμ νμΌμ λ°μ΄λ리 μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
48 |
+
# f.write(csv_docs.getvalue()) # CSV λ¬Έμμ λ΄μ©μ μμ νμΌμ μλλ€.
|
49 |
+
|
50 |
+
# csv_loader = CSVLoader(temp_filepath) # CSVLoaderλ₯Ό μ¬μ©ν΄ CSV λ¬Έμλ₯Ό λ‘λν©λλ€.
|
51 |
+
# csv_doc = csv_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
52 |
+
# return csv_doc # μΆμΆλ ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
53 |
+
|
54 |
+
# def get_json_file(json_docs):
|
55 |
+
# temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
56 |
+
# temp_filepath = os.path.join(temp_dir.name, json_docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
57 |
+
|
58 |
+
# with open(temp_filepath, "wb") as f: # μμ νμΌμ ν
μ€νΈ μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
59 |
+
# f.write(json_docs.getvalue()) # JSON λ¬Έμμ λ΄μ©μ μμ νμΌμ μλλ€.
|
60 |
+
|
61 |
+
# json_loader = JSONLoader(temp_filepath) # JSONLoaderλ₯Ό μ¬μ©ν΄ JSON λ¬Έμλ₯Ό λ‘λν©λλ€.
|
62 |
+
# json_doc = json_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
63 |
+
# return json_doc # μΆμΆλ ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
# # def get_text_file(text_docs):
|
69 |
+
# #
|
70 |
+
# # pass
|
71 |
+
# #
|
72 |
+
# # def get_csv_file(csv_docs):
|
73 |
+
# # pass
|
74 |
+
# #
|
75 |
+
# # def get_json_file(json_docs):
|
76 |
+
# #
|
77 |
+
# #
|
78 |
+
# # pass
|
79 |
+
|
80 |
+
|
81 |
+
# # λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
82 |
+
# def get_text_chunks(documents):
|
83 |
+
# text_splitter = RecursiveCharacterTextSplitter(
|
84 |
+
# chunk_size=1000, # μ²ν¬μ ν¬κΈ°λ₯Ό μ§μ ν©λλ€.
|
85 |
+
# chunk_overlap=200, # μ²ν¬ μ¬μ΄μ μ€λ³΅μ μ§μ ν©λλ€.
|
86 |
+
# length_function=len # ν
μ€νΈμ κΈΈμ΄λ₯Ό μΈ‘μ νλ ν¨μλ₯Ό μ§μ ν©λλ€.
|
87 |
+
# )
|
88 |
+
|
89 |
+
# documents = text_splitter.split_documents(documents) # λ¬Έμλ€μ μ²ν¬λ‘ λλλλ€.
|
90 |
+
# return documents # λλ μ²ν¬λ₯Ό λ°νν©λλ€.
|
91 |
+
|
92 |
+
|
93 |
+
# # ν
μ€νΈ μ²ν¬λ€λ‘λΆν° λ²‘ν° μ€ν μ΄λ₯Ό μμ±νλ ν¨μμ
λλ€.
|
94 |
+
# def get_vectorstore(text_chunks):
|
95 |
+
# # μνλ μλ² λ© λͺ¨λΈμ λ‘λν©λλ€.
|
96 |
+
# embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L12-v2',
|
97 |
+
# model_kwargs={'device': 'cpu'}) # μλ² λ© λͺ¨λΈμ μ€μ ν©λλ€.
|
98 |
+
# vectorstore = FAISS.from_documents(text_chunks, embeddings) # FAISS λ²‘ν° μ€ν μ΄λ₯Ό μμ±ν©λλ€.
|
99 |
+
# return vectorstore # μμ±λ λ²‘ν° μ€ν μ΄λ₯Ό λ°νν©λλ€.
|
100 |
+
|
101 |
+
|
102 |
+
# def get_conversation_chain(vectorstore):
|
103 |
+
# model_name_or_path = 'TheBloke/Llama-2-7B-chat-GGUF'
|
104 |
+
# model_basename = 'llama-2-7b-chat.Q2_K.gguf'
|
105 |
+
# model_path = hf_hub_download(repo_id=model_name_or_path, filename=model_basename)
|
106 |
+
|
107 |
+
# llm = LlamaCpp(model_path=model_path,
|
108 |
+
# n_ctx=8192,
|
109 |
+
# input={"temperature": 0.75, "max_length": 2000, "top_p": 1},
|
110 |
+
# verbose=True, )
|
111 |
+
# # λν κΈ°λ‘μ μ μ₯νκΈ° μν λ©λͺ¨λ¦¬λ₯Ό μμ±ν©λλ€.
|
112 |
+
# memory = ConversationBufferMemory(
|
113 |
+
# memory_key='chat_history', return_messages=True)
|
114 |
+
# # λν κ²μ 체μΈμ μμ±ν©λλ€.
|
115 |
+
# conversation_chain = ConversationalRetrievalChain.from_llm(
|
116 |
+
# llm=llm,
|
117 |
+
# retriever=vectorstore.as_retriever(),
|
118 |
+
# memory=memory
|
119 |
+
# )
|
120 |
+
# return conversation_chain # μμ±λ λν 체μΈμ λ°νν©λλ€.
|
121 |
+
|
122 |
+
# # μ¬μ©μ μ
λ ₯μ μ²λ¦¬νλ ν¨μμ
λλ€.
|
123 |
+
# def handle_userinput(user_question):
|
124 |
+
# print('user_question => ', user_question)
|
125 |
+
# # λν 체μΈμ μ¬μ©νμ¬ μ¬μ©μ μ§λ¬Έμ λν μλ΅μ μμ±ν©λλ€.
|
126 |
+
# response = st.session_state.conversation({'question': user_question})
|
127 |
+
# # λν κΈ°λ‘μ μ μ₯ν©λλ€.
|
128 |
+
# st.session_state.chat_history = response['chat_history']
|
129 |
+
|
130 |
+
# for i, message in enumerate(st.session_state.chat_history):
|
131 |
+
# if i % 2 == 0:
|
132 |
+
# st.write(user_template.replace(
|
133 |
+
# "{{MSG}}", message.content), unsafe_allow_html=True)
|
134 |
+
# else:
|
135 |
+
# st.write(bot_template.replace(
|
136 |
+
# "{{MSG}}", message.content), unsafe_allow_html=True)
|
137 |
+
# text_chunks = []
|
138 |
+
# def initialize_conversation_chain():
|
139 |
+
# # Add the necessary code to initialize the conversation_chain
|
140 |
+
# # This may include loading the LlamaCpp model and creating the conversation_chain
|
141 |
+
# vectorstore = get_vectorstore(text_chunks) # Replace this with the appropriate code
|
142 |
+
# return get_conversation_chain(vectorstore)
|
143 |
+
|
144 |
+
|
145 |
+
# def main():
|
146 |
+
# load_dotenv()
|
147 |
+
# st.set_page_config(page_title="Chat with multiple Files",
|
148 |
+
# page_icon=":books:")
|
149 |
+
# st.write(css, unsafe_allow_html=True)
|
150 |
+
|
151 |
+
# # λν 체μΈμ΄ μΈμ
μνμ μκ±°λ NoneμΈ κ²½μ° μ΄κΈ°νν©λλ€.
|
152 |
+
# if "conversation" not in st.session_state or st.session_state.conversation is None:
|
153 |
+
# # μ μ ν λ°μ΄ν°λ‘ text_chunksλ₯Ό μ μν΄μΌ ν©λλ€.
|
154 |
+
# st.session_state.conversation = initialize_conversation_chain(text_chunks)
|
155 |
+
# # if "conversation" not in st.session_state:
|
156 |
+
# # st.session_state.conversation = None
|
157 |
+
# # if "chat_history" not in st.session_state:
|
158 |
+
# # st.session_state.chat_history = None
|
159 |
+
|
160 |
+
# st.header("Chat with multiple Files:")
|
161 |
+
# user_question = st.text_input("Ask a question about your documents:")
|
162 |
+
# # if user_question:
|
163 |
+
# # handle_userinput(user_question)
|
164 |
+
# if user_question:
|
165 |
+
# # Ensure that conversation_chain is initialized before calling handle_userinput
|
166 |
+
# if st.session_state.conversation is None:
|
167 |
+
# st.session_state.conversation = initialize_conversation_chain()
|
168 |
+
|
169 |
+
# handle_userinput(user_question)
|
170 |
+
|
171 |
+
# with st.sidebar:
|
172 |
+
# st.subheader("Your documents")
|
173 |
+
# docs = st.file_uploader(
|
174 |
+
# "Upload your PDFs here and click on 'Process'", accept_multiple_files=True)
|
175 |
+
# if st.button("Process"):
|
176 |
+
# with st.spinner("Processing"):
|
177 |
+
# # get pdf text
|
178 |
+
# doc_list = []
|
179 |
+
|
180 |
+
# for file in docs:
|
181 |
+
# print('file - type : ', file.type)
|
182 |
+
# if file.type == 'text/plain':
|
183 |
+
# # file is .txt
|
184 |
+
# doc_list.extend(get_text_file(file))
|
185 |
+
# elif file.type in ['application/octet-stream', 'application/pdf']:
|
186 |
+
# # file is .pdf
|
187 |
+
# doc_list.extend(get_pdf_text(file))
|
188 |
+
# elif file.type == 'text/csv':
|
189 |
+
# # file is .csv
|
190 |
+
# doc_list.extend(get_csv_file(file))
|
191 |
+
# elif file.type == 'application/json':
|
192 |
+
# # file is .json
|
193 |
+
# doc_list.extend(get_json_file(file))
|
194 |
+
|
195 |
+
# # get the text chunks
|
196 |
+
# text_chunks = get_text_chunks(doc_list)
|
197 |
+
|
198 |
+
# # create vector store
|
199 |
+
# vectorstore = get_vectorstore(text_chunks)
|
200 |
+
|
201 |
+
# # create conversation chain
|
202 |
+
# st.session_state.conversation = get_conversation_chain(
|
203 |
+
# vectorstore)
|
204 |
+
|
205 |
+
|
206 |
+
# if __name__ == '__main__':
|
207 |
+
# main()
|
208 |
+
|
209 |
import streamlit as st
|
210 |
from dotenv import load_dotenv
|
211 |
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
|
|
219 |
from pathlib import Path
|
220 |
from pprint import pprint
|
221 |
|
|
|
|
|
|
|
|
|
|
|
222 |
# PDF λ¬Έμλ‘λΆν° ν
μ€νΈλ₯Ό μΆμΆνλ ν¨μμ
λλ€.
|
223 |
def get_pdf_text(pdf_docs):
|
224 |
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
|
|
229 |
pdf_doc = pdf_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
230 |
return pdf_doc # μΆμΆν ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
231 |
|
|
|
|
|
|
|
232 |
def get_text_file(text_docs):
|
233 |
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
234 |
temp_filepath = os.path.join(temp_dir.name, text_docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
|
|
262 |
json_doc = json_loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
263 |
return json_doc # μΆμΆλ ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
267 |
def get_text_chunks(documents):
|
|
|
290 |
model_path = hf_hub_download(repo_id=model_name_or_path, filename=model_basename)
|
291 |
|
292 |
llm = LlamaCpp(model_path=model_path,
|
293 |
+
n_ctx=4086,
|
294 |
input={"temperature": 0.75, "max_length": 2000, "top_p": 1},
|
295 |
verbose=True, )
|
296 |
# λν κΈ°λ‘μ μ μ₯νκΈ° μν λ©λͺ¨λ¦¬λ₯Ό μμ±ν©λλ€.
|
|
|
319 |
else:
|
320 |
st.write(bot_template.replace(
|
321 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
|
323 |
|
324 |
def main():
|
|
|
327 |
page_icon=":books:")
|
328 |
st.write(css, unsafe_allow_html=True)
|
329 |
|
330 |
+
if "conversation" not in st.session_state:
|
331 |
+
st.session_state.conversation = None
|
332 |
+
if "chat_history" not in st.session_state:
|
333 |
+
st.session_state.chat_history = None
|
|
|
|
|
|
|
|
|
334 |
|
335 |
st.header("Chat with multiple Files:")
|
336 |
user_question = st.text_input("Ask a question about your documents:")
|
|
|
|
|
337 |
if user_question:
|
|
|
|
|
|
|
|
|
338 |
handle_userinput(user_question)
|
339 |
|
340 |
with st.sidebar:
|
|
|
373 |
|
374 |
|
375 |
if __name__ == '__main__':
|
376 |
+
main()
|