Update app.py
Browse files
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
|
| 53 |
self.file_path = file_path
|
| 54 |
-
self.jq_schema = jq_schema
|
| 55 |
|
| 56 |
def load(self):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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):
|