Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -158,23 +158,25 @@ if uploaded_files:
|
|
158 |
chunkdf = []
|
159 |
for i, chunk in enumerate(text_chunk):
|
160 |
inp = chunk
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
178 |
# df = pd.DataFrame(repair_json(tablex_chain.run(inp)[0]))
|
179 |
chunkdf.append(df)
|
180 |
|
|
|
158 |
chunkdf = []
|
159 |
for i, chunk in enumerate(text_chunk):
|
160 |
inp = chunk
|
161 |
+
try:
|
162 |
+
# Assuming tablex_chain.run(inp)[0] returns a dictionary
|
163 |
+
original_dict = tablex_chain.run(inp)[0]
|
164 |
+
# Convert the dictionary to a JSON string
|
165 |
+
json_str = json.dumps(original_dict)
|
166 |
+
# Replace single quotes with double quotes in the JSON string
|
167 |
+
json_str_fixed = json_str.replace("'", '"')
|
168 |
+
# Use literal_eval to safely evaluate the JSON string as a Python dictionary
|
169 |
+
fixed_dict = literal_eval(json_str_fixed)
|
170 |
+
# Create a DataFrame from the fixed dictionary
|
171 |
+
df = pd.DataFrame(fixed_dict, index=[0]).fillna('')
|
172 |
+
except:
|
173 |
+
try:
|
174 |
+
df = pd.DataFrame(literal_eval(str(json.dumps(tablex_chain.run(inp)[0])).replace("\'", '\"')), index=[0]).fillna('')
|
175 |
+
except:
|
176 |
+
try:
|
177 |
+
df = pd.DataFrame(literal_eval(str(json.dumps(tablex_chain.run(inp)[0]) + ']').replace("\'", '\"')), index=[0]).fillna('')
|
178 |
+
except SyntaxError:
|
179 |
+
df = pd.DataFrame(literal_eval('[' + str(json.dumps(tablex_chain.run(inp)[0]) + ']').replace("\'", '\"')), index=[0]).fillna('')
|
180 |
# df = pd.DataFrame(repair_json(tablex_chain.run(inp)[0]))
|
181 |
chunkdf.append(df)
|
182 |
|