namkwonwoo commited on
Commit
5b9f44d
Β·
1 Parent(s): 42fabaa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -44,30 +44,18 @@ def get_csv_file(csv_docs):
44
  return csv_doc
45
 
46
  import json
47
- import mimetypes
48
-
49
  def get_json_file(docs):
 
 
 
 
50
  text_list = []
51
-
52
- for file in docs:
53
- # Use file extension to identify JSON files
54
- file_extension = file.name.split('.')[-1].lower()
55
-
56
- if file_extension == 'json':
57
- # Read the JSON content from the file
58
- json_content = json.loads(file.getvalue().decode('utf-8'))
59
-
60
- # Extract text from the JSON content
61
- if isinstance(json_content, dict):
62
- text = ' '.join(str(value) for value in json_content.values())
63
- text_list.append(text)
64
- elif isinstance(json_content, list):
65
- text = ' '.join(str(item) for item in json_content)
66
- text_list.append(text)
67
-
68
  return text_list
69
 
70
-
71
 
72
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
73
  def get_text_chunks(documents):
 
44
  return csv_doc
45
 
46
  import json
 
 
47
  def get_json_file(docs):
48
+ # Assuming docs is a file-like object from st.file_uploader
49
+ json_docs = json.load(docs)
50
+
51
+ # Extracting text from the JSON structure (modify this part based on your JSON structure)
52
  text_list = []
53
+ for item in json_docs:
54
+ if 'text' in item:
55
+ text_list.append(item['text'])
56
+
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  return text_list
58
 
 
59
 
60
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
61
  def get_text_chunks(documents):