firqaaa commited on
Commit
90e2c42
1 Parent(s): 7cf4a25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -158,23 +158,25 @@ if uploaded_files:
158
  chunkdf = []
159
  for i, chunk in enumerate(text_chunk):
160
  inp = chunk
161
- # Assuming tablex_chain.run(inp)[0] returns a dictionary
162
- original_dict = tablex_chain.run(inp)[0]
163
- # Convert the dictionary to a JSON string
164
- json_str = json.dumps(original_dict)
165
- # Replace single quotes with double quotes in the JSON string
166
- json_str_fixed = json_str.replace("'", '"')
167
- # Use literal_eval to safely evaluate the JSON string as a Python dictionary
168
- fixed_dict = literal_eval(json_str_fixed)
169
- # Create a DataFrame from the fixed dictionary
170
- df = pd.DataFrame(fixed_dict, index=[0]).fillna('')
171
- # try:
172
- # df = pd.DataFrame(literal_eval(str(json.dumps(tablex_chain.run(inp)[0])).replace("\'", '\"')), index=[0]).fillna('')
173
- # except:
174
- # try:
175
- # df = pd.DataFrame(literal_eval(str(json.dumps(tablex_chain.run(inp)[0]) + ']').replace("\'", '\"')), index=[0]).fillna('')
176
- # except SyntaxError:
177
- # df = pd.DataFrame(literal_eval('[' + str(json.dumps(tablex_chain.run(inp)[0]) + ']').replace("\'", '\"')), index=[0]).fillna('')
 
 
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