Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,21 +25,24 @@ st.markdown('###### ์ง๋ฌธ, ์์ฝ ๋ฑ ๋ค์ํ ๋ถํ์ ํด ๋ณด์ธ์! ๊ต๊ณผ
|
|
25 |
|
26 |
|
27 |
api_key = st.text_input(label='OpenAI API ํค๋ฅผ ์
๋ ฅํ์ธ์', type='password')
|
28 |
-
|
29 |
|
30 |
|
31 |
if api_key:
|
32 |
# OpenAI API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ ์ฒ๋ฆฌ ๊ณผ์ ์ ํจ์๋ก ์ ์
|
33 |
-
def initialize_openai_processing():
|
34 |
-
|
|
|
|
|
|
|
35 |
loader = DirectoryLoader('./khistory_data', glob="*.txt", loader_cls=TextLoader)
|
36 |
documents = loader.load()
|
37 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=600, chunk_overlap=100)
|
38 |
texts = text_splitter.split_documents(documents)
|
39 |
|
40 |
persist_directory = 'db'
|
41 |
-
embedding = OpenAIEmbeddings()
|
42 |
-
|
43 |
vectordb = Chroma.from_documents(
|
44 |
documents=texts,
|
45 |
embedding=embedding,
|
@@ -54,7 +57,8 @@ if api_key:
|
|
54 |
retriever = vectordb.as_retriever(search_kwargs={"k": 3})
|
55 |
|
56 |
qa_chain = RetrievalQA.from_chain_type(
|
57 |
-
llm=OpenAI(),
|
|
|
58 |
chain_type="stuff",
|
59 |
retriever=retriever,
|
60 |
return_source_documents=True)
|
@@ -62,7 +66,7 @@ if api_key:
|
|
62 |
return embedding, vectordb, qa_chain
|
63 |
|
64 |
# ํจ์ ํธ์ถ๋ก ์ด๊ธฐํ ๊ณผ์ ์ํ
|
65 |
-
embedding, vectordb, qa_chain = initialize_openai_processing()
|
66 |
|
67 |
|
68 |
# ํ
์คํธ ์
๋ ฅ
|
|
|
25 |
|
26 |
|
27 |
api_key = st.text_input(label='OpenAI API ํค๋ฅผ ์
๋ ฅํ์ธ์', type='password')
|
28 |
+
|
29 |
|
30 |
|
31 |
if api_key:
|
32 |
# OpenAI API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ ์ฒ๋ฆฌ ๊ณผ์ ์ ํจ์๋ก ์ ์
|
33 |
+
def initialize_openai_processing(api_key):
|
34 |
+
#client = OpenAI()
|
35 |
+
#OpenAI.api_key = api_key
|
36 |
+
|
37 |
+
|
38 |
loader = DirectoryLoader('./khistory_data', glob="*.txt", loader_cls=TextLoader)
|
39 |
documents = loader.load()
|
40 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=600, chunk_overlap=100)
|
41 |
texts = text_splitter.split_documents(documents)
|
42 |
|
43 |
persist_directory = 'db'
|
44 |
+
#embedding = OpenAIEmbeddings()
|
45 |
+
embedding = OpenAIEmbeddings(api_key=api_key) # API ํค๋ฅผ ์์ฑ์์ ์ ๋ฌ
|
46 |
vectordb = Chroma.from_documents(
|
47 |
documents=texts,
|
48 |
embedding=embedding,
|
|
|
57 |
retriever = vectordb.as_retriever(search_kwargs={"k": 3})
|
58 |
|
59 |
qa_chain = RetrievalQA.from_chain_type(
|
60 |
+
#llm=OpenAI(),
|
61 |
+
llm=OpenAI(api_key=api_key),
|
62 |
chain_type="stuff",
|
63 |
retriever=retriever,
|
64 |
return_source_documents=True)
|
|
|
66 |
return embedding, vectordb, qa_chain
|
67 |
|
68 |
# ํจ์ ํธ์ถ๋ก ์ด๊ธฐํ ๊ณผ์ ์ํ
|
69 |
+
embedding, vectordb, qa_chain = initialize_openai_processing(api_key)
|
70 |
|
71 |
|
72 |
# ํ
์คํธ ์
๋ ฅ
|