Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,14 +29,33 @@ def get_pdf_text(pdf_docs):
|
|
29 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
30 |
|
31 |
def get_text_file(docs):
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
def get_csv_file(docs):
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
def get_json_file(docs):
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
|
|
29 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
30 |
|
31 |
def get_text_file(docs):
|
32 |
+
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
33 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
34 |
+
with open(temp_filepath, "wb") as f: # μμ νμΌμ λ°μ΄λ리 μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
35 |
+
f.write(docs.getvalue()) # PDF λ¬Έμμ λ΄μ©μ μμ νμΌμ μλλ€.
|
36 |
+
loader = TextLoader(temp_filepath) # PyPDFLoaderλ₯Ό μ¬μ©ν΄ PDFλ₯Ό λ‘λν©λλ€.
|
37 |
+
docs = loader.load() # ν
μ€νΈλ₯Ό μΆμΆν©λλ€.
|
38 |
+
return docs # μΆμΆν ν
μ€νΈλ₯Ό λ°νν©λλ€.
|
39 |
|
40 |
|
41 |
def get_csv_file(docs):
|
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 |
+
loader = CSVLoader(temp_filepath)
|
48 |
+
data = loader.load()
|
49 |
+
return data
|
50 |
|
51 |
def get_json_file(docs):
|
52 |
+
temp_dir = tempfile.TemporaryDirectory()
|
53 |
+
temp_filepath = os.path.join(temp_dir.name, docs.name)
|
54 |
+
with open(temp_filepath, "wb") as f: # μμ νμΌμ λ°μ΄λ리 μ°κΈ° λͺ¨λλ‘ μ½λλ€.
|
55 |
+
f.write(docs.getvalue())
|
56 |
+
loader = JSONLoader(file_path = temp_filepath, jq_schema ='.users[].homepage', text_content=False)
|
57 |
+
data = loader.load()
|
58 |
+
return data
|
59 |
|
60 |
|
61 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|