Update src/streamlit_app.py
Browse files- src/streamlit_app.py +22 -15
src/streamlit_app.py
CHANGED
|
@@ -41,16 +41,11 @@ def get_text_file(docs):
|
|
| 41 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
| 42 |
|
| 43 |
temp_dir = tempfile.TemporaryDirectory()
|
| 44 |
-
temp_filepath = os.path.join(temp_dir.name,
|
| 45 |
-
|
| 46 |
-
|
| 47 |
with open(temp_filepath, "wb") as f:
|
| 48 |
-
f.write(
|
| 49 |
-
|
| 50 |
-
|
| 51 |
text_loader = TextLoader(temp_filepath, encoding="utf-8")
|
| 52 |
-
text_doc = text_loader.load()
|
| 53 |
-
|
| 54 |
return text_doc
|
| 55 |
|
| 56 |
|
|
@@ -58,16 +53,12 @@ def get_csv_file(docs):
|
|
| 58 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
| 59 |
|
| 60 |
temp_dir = tempfile.TemporaryDirectory()
|
| 61 |
-
temp_filepath = os.path.join(temp_dir.name,
|
| 62 |
-
|
| 63 |
-
|
| 64 |
with open(temp_filepath, "wb") as f:
|
| 65 |
-
f.write(
|
| 66 |
-
|
| 67 |
-
|
| 68 |
csv_loader = CSVLoader(
|
| 69 |
file_path=temp_filepath,
|
| 70 |
-
encoding="utf-8",
|
| 71 |
)
|
| 72 |
csv_doc = csv_loader.load()
|
| 73 |
return csv_doc
|
|
@@ -214,8 +205,24 @@ def main():
|
|
| 214 |
|
| 215 |
################## TXT, CSV ๋ฒํผ ๊ตฌํ
|
| 216 |
# TXT ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/plain':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
# CSV ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/csv':
|
| 218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
if st.button("Process[JSON]"):
|
| 220 |
with st.spinner("Processing"):
|
| 221 |
# get txt text
|
|
|
|
| 41 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
| 42 |
|
| 43 |
temp_dir = tempfile.TemporaryDirectory()
|
| 44 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
|
|
|
|
|
|
| 45 |
with open(temp_filepath, "wb") as f:
|
| 46 |
+
f.write(docs.getvalue())
|
|
|
|
|
|
|
| 47 |
text_loader = TextLoader(temp_filepath, encoding="utf-8")
|
| 48 |
+
text_doc = text_loader.load()
|
|
|
|
| 49 |
return text_doc
|
| 50 |
|
| 51 |
|
|
|
|
| 53 |
#################### ๋ด์ฉ์ ์ถ๊ฐํ ๋ถ๋ถ
|
| 54 |
|
| 55 |
temp_dir = tempfile.TemporaryDirectory()
|
| 56 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
|
|
|
|
|
|
| 57 |
with open(temp_filepath, "wb") as f:
|
| 58 |
+
f.write(docs.getvalue())
|
|
|
|
|
|
|
| 59 |
csv_loader = CSVLoader(
|
| 60 |
file_path=temp_filepath,
|
| 61 |
+
encoding="utf-8",
|
| 62 |
)
|
| 63 |
csv_doc = csv_loader.load()
|
| 64 |
return csv_doc
|
|
|
|
| 205 |
|
| 206 |
################## TXT, CSV ๋ฒํผ ๊ตฌํ
|
| 207 |
# TXT ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/plain':
|
| 208 |
+
if st.button("Process[TXT]"):
|
| 209 |
+
with st.spinner("Processing"):
|
| 210 |
+
doc_list = []
|
| 211 |
+
for file in docs:
|
| 212 |
+
if file.type == "text/plain":
|
| 213 |
+
doc_list.extend(get_text_file(file))
|
| 214 |
+
else:
|
| 215 |
+
st.error("TXT ํ์ผ์ด ์๋๋๋ค.")
|
| 216 |
# CSV ๋ฒํผ ๊ตฌํ ์ฐธ๊ณ : if file.type == 'text/csv':
|
| 217 |
|
| 218 |
+
if st.button("Process[CSV]"):
|
| 219 |
+
with st.spinner("Processing"):
|
| 220 |
+
doc_list = []
|
| 221 |
+
for file in docs:
|
| 222 |
+
if file.type == "text/csv":
|
| 223 |
+
doc_list.extend(get_csv_file(file))
|
| 224 |
+
else:
|
| 225 |
+
st.error("CSV ํ์ผ์ด ์๋๋๋ค.")
|
| 226 |
if st.button("Process[JSON]"):
|
| 227 |
with st.spinner("Processing"):
|
| 228 |
# get txt text
|