[email protected]
commited on
Commit
Β·
b2646b2
1
Parent(s):
30fbdf8
edit codes
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from dotenv import load_dotenv
|
3 |
from PyPDF2 import PdfReader
|
@@ -29,16 +31,38 @@ def get_pdf_text(pdf_docs):
|
|
29 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
30 |
|
31 |
def get_text_file(docs):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
|
37 |
def get_csv_file(docs):
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
def get_json_file(docs):
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
|
|
1 |
+
import csv
|
2 |
+
import json
|
3 |
import streamlit as st
|
4 |
from dotenv import load_dotenv
|
5 |
from PyPDF2 import PdfReader
|
|
|
31 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
32 |
|
33 |
def get_text_file(docs):
|
34 |
+
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
35 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
36 |
+
with open(temp_filepath, "wb") as f: # μμ νμΌμ λ°μ΄λ리 μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
37 |
+
f.write(docs.getvalue()) # TXT λ¬Έμμ λ΄μ©μ μμ νμΌμ μλλ€.
|
38 |
+
with open(temp_filepath, "r") as txt_file: # TXT νμΌμ λ°μ΄λ리 μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
39 |
+
txt_doc = txt_file.read() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
40 |
+
return txt_doc # μΆμΆν ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
41 |
|
42 |
def get_csv_file(docs):
|
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 |
+
|
48 |
+
csv_data = []
|
49 |
+
with open(temp_filepath, "r") as csv_file:
|
50 |
+
csv_reader = csv.reader(csv_file)
|
51 |
+
for row in csv_reader:
|
52 |
+
csv_data.append(row)
|
53 |
+
|
54 |
+
return csv_data
|
55 |
|
56 |
def get_json_file(docs):
|
57 |
+
temp_dir = tempfile.TemporaryDirectory()
|
58 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
59 |
+
with open(temp_filepath, "wb") as f:
|
60 |
+
f.write(docs.getvalue())
|
61 |
+
|
62 |
+
with open(temp_filepath, "r") as json_file:
|
63 |
+
json_data = json.load(json_file)
|
64 |
+
|
65 |
+
return json_data
|
66 |
|
67 |
|
68 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|