Spaces:
Running
Running
File size: 911 Bytes
c7b1d79 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import json
def extract_json_from_response(content: str):
# Remove Markdown code block markers
if content.startswith("```json"):
content = content.replace("```json", "").strip()
if content.endswith("```"):
content = content[:-3].strip()
# Now it's safe to parse the cleaned JSON
return json.loads(content)
def extract_classification(response_content: str) -> str:
try:
if response_content.startswith("```json"):
response_content = response_content.replace("```json", "").strip()
if response_content.endswith("```"):
response_content = response_content[:-3].strip()
parsed = json.loads(response_content)
return parsed["final_consensus"]["classification"]
except Exception as e:
# Log the error or handle it as needed
print(f"Error parsing classification: {e}")
return "ParsingError"
|