nijoow commited on
Commit
a2b4843
Β·
1 Parent(s): 74e5908

Rename app (2).py to app.py

Browse files
Files changed (1) hide show
  1. app (2).py β†’ app.py +28 -4
app (2).py β†’ app.py RENAMED
@@ -27,16 +27,40 @@ def get_pdf_text(pdf_docs):
27
 
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
-
31
  def get_text_file(docs):
32
- pass
 
 
 
 
 
 
 
 
33
 
 
 
 
34
 
35
  def get_csv_file(docs):
36
- pass
 
 
 
 
 
 
 
 
37
 
38
  def get_json_file(docs):
39
- pass
 
 
 
 
 
 
40
 
41
 
42
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
27
 
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
 
30
  def get_text_file(docs):
31
+ with NamedTemporaryFile() as temp_file:
32
+ temp_file.write(docs.getvalue())
33
+ temp_file.seek(0)
34
+
35
+ # ν…μŠ€νŠΈ νŒŒμΌμ—μ„œ ν…μŠ€νŠΈλ₯Ό μΆ”μΆœν•˜λŠ” λ‘œμ§μ„ κ΅¬ν˜„ν•©λ‹ˆλ‹€.
36
+ text_content = temp_file.read().decode('utf-8')
37
+
38
+ return text_content
39
+
40
 
41
+ import csv
42
+ import json
43
+ from tempfile import NamedTemporaryFile
44
 
45
  def get_csv_file(docs):
46
+ with NamedTemporaryFile() as temp_file:
47
+ temp_file.write(docs.getvalue())
48
+ temp_file.seek(0)
49
+
50
+ csv_data = []
51
+ csv_reader = csv.reader(temp_file)
52
+ for row in csv_reader:
53
+ csv_data.append(row)
54
+ return csv_data
55
 
56
  def get_json_file(docs):
57
+ with NamedTemporaryFile() as temp_file:
58
+ temp_file.write(docs.getvalue())
59
+ temp_file.seek(0)
60
+
61
+ json_data = json.load(temp_file)
62
+ return json_data
63
+
64
 
65
 
66
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.