Spaces:
Sleeping
Sleeping
Update chat.py
Browse files
chat.py
CHANGED
@@ -338,16 +338,17 @@ def unstructured_text_to_df(text):
|
|
338 |
# Debugging: Print raw response to check its format
|
339 |
print("Raw Response:", response_content)
|
340 |
|
341 |
-
#
|
342 |
-
|
343 |
-
|
344 |
-
start_index = response_content.find("{")
|
345 |
-
json_part = response_content[start_index:] # Extract starting from the first '{'
|
346 |
-
structured_data = json.loads(json_part) # Parse the JSON part
|
347 |
|
|
|
|
|
|
|
348 |
print("Parsed JSON:", structured_data)
|
349 |
-
except
|
350 |
-
print(
|
|
|
351 |
|
352 |
|
353 |
# Convert the structured data into a DataFrame
|
|
|
338 |
# Debugging: Print raw response to check its format
|
339 |
print("Raw Response:", response_content)
|
340 |
|
341 |
+
# Step 1: Extract the JSON part from the markdown
|
342 |
+
# Split the response content to isolate the JSON part
|
343 |
+
json_part = response_content.split("```json\n")[1].split("\n```")[0]
|
|
|
|
|
|
|
344 |
|
345 |
+
# Step 2: Parse the JSON content
|
346 |
+
try:
|
347 |
+
structured_data = json.loads(json_part) # Parse the JSON content
|
348 |
print("Parsed JSON:", structured_data)
|
349 |
+
except json.JSONDecodeError:
|
350 |
+
print("Error: Response content is not valid JSON.")
|
351 |
+
|
352 |
|
353 |
|
354 |
# Convert the structured data into a DataFrame
|