Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -134,14 +134,21 @@ This JSON format will be used to store and manage invoices in a structured and u
|
|
| 134 |
max_tokens=16384
|
| 135 |
)
|
| 136 |
content = response.choices[0].message.content.strip()
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
# Step 2: Parse the cleaned content as JSON
|
| 141 |
#parsed_content = json.loads(cleaned_content)
|
| 142 |
|
| 143 |
# Step 3: Print the parsed JSON object
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
except Exception as e:
|
| 146 |
return f"Error in summarization: {str(e)}"
|
| 147 |
# Dependency to check API Key
|
|
|
|
| 134 |
max_tokens=16384
|
| 135 |
)
|
| 136 |
content = response.choices[0].message.content.strip()
|
| 137 |
+
cleaned_content = re.sub(r'^```json\n', '', content) # Remove '```json\n' at the beginning
|
| 138 |
+
cleaned_content = re.sub(r'\n```$', '', cleaned_content) # Remove '\n```' at the end
|
| 139 |
|
| 140 |
# Step 2: Parse the cleaned content as JSON
|
| 141 |
#parsed_content = json.loads(cleaned_content)
|
| 142 |
|
| 143 |
# Step 3: Print the parsed JSON object
|
| 144 |
+
try:
|
| 145 |
+
parsed_content = json.loads(cleaned_content)
|
| 146 |
+
return parsed_content
|
| 147 |
+
except json.JSONDecodeError as e:
|
| 148 |
+
print("Error parsing JSON:", e)
|
| 149 |
+
# Optionally, print the cleaned content to debug
|
| 150 |
+
print("Cleaned content:", cleaned_content)
|
| 151 |
+
return None
|
| 152 |
except Exception as e:
|
| 153 |
return f"Error in summarization: {str(e)}"
|
| 154 |
# Dependency to check API Key
|