han-byeol commited on
Commit
2ee967a
Β·
1 Parent(s): f3ac5cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -49,26 +49,32 @@ def get_csv_file(csv_docs):
49
  return csv_doc
50
 
51
  class JSONLoader:
52
- def __init__(self, file_path, jq_schema):
53
  self.file_path = file_path
54
- self.jq_schema = jq_schema
55
 
56
  def load(self):
57
- with open(self.file_path, 'r') as json_file:
58
- data = json.load(json_file)
59
- # μ—¬κΈ°μ„œ jq_schemaλ₯Ό ν™œμš©ν•˜μ—¬ 데이터λ₯Ό μ²˜λ¦¬ν•˜λŠ” μž‘μ—…μ„ μˆ˜ν–‰ν•  κ²ƒμœΌλ‘œ κ°€μ •ν•©λ‹ˆλ‹€.
60
- processed_data = process_with_schema(data, self.jq_schema)
61
- return processed_data
 
 
 
 
 
 
62
 
63
  def get_json_file(json_docs):
64
  temp_dir = tempfile.TemporaryDirectory()
65
  temp_filepath = os.path.join(temp_dir.name, json_docs.name)
66
  with open(temp_filepath, "wb") as f:
67
  f.write(json_docs.getvalue())
68
- json_loader = JSONLoader(temp_filepath, jq_schema={})
69
  json_doc = json_loader.load()
70
  return json_doc
71
 
 
72
 
73
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
74
  def get_text_chunks(documents):
 
49
  return csv_doc
50
 
51
  class JSONLoader:
52
+ def __init__(self, file_path):
53
  self.file_path = file_path
 
54
 
55
  def load(self):
56
+ try:
57
+ with open(self.file_path, 'r', encoding='utf-8') as json_file:
58
+ data = json.load(json_file)
59
+ # JSON 파일 μ•ˆμ— νŠΉμ • ν•„λ“œμ— μžˆλŠ” ν…μŠ€νŠΈ μΆ”μΆœν•˜λŠ” λΆ€λΆ„
60
+ if 'text_field_name' in data: # 'text_field_name'은 μ‹€μ œ JSON νŒŒμΌμ—μ„œ ν…μŠ€νŠΈκ°€ μžˆλŠ” ν•„λ“œλͺ…μž…λ‹ˆλ‹€.
61
+ text = data['text_field_name']
62
+ return text
63
+ else:
64
+ return "Text field not found in JSON"
65
+ except Exception as e:
66
+ return str(e)
67
 
68
  def get_json_file(json_docs):
69
  temp_dir = tempfile.TemporaryDirectory()
70
  temp_filepath = os.path.join(temp_dir.name, json_docs.name)
71
  with open(temp_filepath, "wb") as f:
72
  f.write(json_docs.getvalue())
73
+ json_loader = JSONLoader(temp_filepath)
74
  json_doc = json_loader.load()
75
  return json_doc
76
 
77
+
78
 
79
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
80
  def get_text_chunks(documents):