Upload streamlit_app.py
Browse files- src/streamlit_app.py +45 -0
src/streamlit_app.py
CHANGED
|
@@ -39,11 +39,23 @@ def get_pdf_text(pdf_docs):
|
|
| 39 |
|
| 40 |
def get_text_file(docs):
|
| 41 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return text_doc
|
| 43 |
|
| 44 |
|
| 45 |
def get_csv_file(docs):
|
| 46 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return csv_doc
|
| 48 |
|
| 49 |
# def get_json_file(docs):
|
|
@@ -188,7 +200,40 @@ def main():
|
|
| 188 |
|
| 189 |
################## TXT, CSV ๋ฒํผ ๊ตฌํ
|
| 190 |
# TXT ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/plain':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
# CSV ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/csv':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
if st.button("Process[JSON]"):
|
| 194 |
with st.spinner("Processing"):
|
|
|
|
| 39 |
|
| 40 |
def get_text_file(docs):
|
| 41 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
| 42 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 43 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
| 44 |
+
with open(temp_filepath, "wb") as f:
|
| 45 |
+
f.write(docs.getvalue())
|
| 46 |
+
docs_loader = TextLoader(temp_filepath)
|
| 47 |
+
text_doc = docs_loader.load()
|
| 48 |
return text_doc
|
| 49 |
|
| 50 |
|
| 51 |
def get_csv_file(docs):
|
| 52 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
| 53 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 54 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
| 55 |
+
with open(temp_filepath, "wb") as f:
|
| 56 |
+
f.write(docs.getvalue())
|
| 57 |
+
csv_loader = CSVLoader(temp_filepath)
|
| 58 |
+
csv_doc = csv_loader.load()
|
| 59 |
return csv_doc
|
| 60 |
|
| 61 |
# def get_json_file(docs):
|
|
|
|
| 200 |
|
| 201 |
################## TXT, CSV ๋ฒํผ ๊ตฌํ
|
| 202 |
# TXT ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/plain':
|
| 203 |
+
if st.button("Process[TXT]"):
|
| 204 |
+
with st.spinner("Processing"):
|
| 205 |
+
doc_list = []
|
| 206 |
+
for file in docs:
|
| 207 |
+
print('file - type : ', file.type)
|
| 208 |
+
if file.type == 'text/plain':
|
| 209 |
+
doc_list.extend(get_text_file(file))
|
| 210 |
+
else:
|
| 211 |
+
st.error("TXT ํ์ผ์ด ์๋๋๋ค.")
|
| 212 |
+
if not doc_list:
|
| 213 |
+
st.error("์ฒ๋ฆฌ ๊ฐ๋ฅํ ๋ฌธ์๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค.")
|
| 214 |
+
st.stop()
|
| 215 |
+
|
| 216 |
+
text_chunks = get_text_chunks(doc_list)
|
| 217 |
+
vectorstore = get_vectorstore(text_chunks)
|
| 218 |
+
st.session_state.conversation = get_conversation_chain(vectorstore)
|
| 219 |
+
|
| 220 |
# CSV ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/csv':
|
| 221 |
+
if st.button("Process[CSV]"):
|
| 222 |
+
with st.spinner("Processing"):
|
| 223 |
+
doc_list = []
|
| 224 |
+
for file in docs:
|
| 225 |
+
print('file - type : ', file.type)
|
| 226 |
+
if file.type == 'text/csv':
|
| 227 |
+
doc_list.extend(get_csv_file(file))
|
| 228 |
+
else:
|
| 229 |
+
st.error("CSV ํ์ผ์ด ์๋๋๋ค.")
|
| 230 |
+
if not doc_list:
|
| 231 |
+
st.error("์ฒ๋ฆฌ ๊ฐ๋ฅํ ๋ฌธ์๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค.")
|
| 232 |
+
st.stop()
|
| 233 |
+
|
| 234 |
+
text_chunks = get_text_chunks(doc_list)
|
| 235 |
+
vectorstore = get_vectorstore(text_chunks)
|
| 236 |
+
st.session_state.conversation = get_conversation_chain(vectorstore)
|
| 237 |
|
| 238 |
if st.button("Process[JSON]"):
|
| 239 |
with st.spinner("Processing"):
|