sujeongim0402@gmail.com commited on
Commit
b2646b2
β€’
1 Parent(s): 30fbdf8

edit codes

Browse files
Files changed (1) hide show
  1. app.py +30 -6
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
- file_path = 'study_plan.txt' # Replace with your file path
33
- with open(file_path, 'r') as text_file:
34
- result = get_text_file(text_file)
35
- print(result)
 
 
 
36
 
37
  def get_csv_file(docs):
38
- pass
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  def get_json_file(docs):
41
- pass
 
 
 
 
 
 
 
 
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
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.