Spaces:
Runtime error
Runtime error
Download src/lib/parseBadJSON.ts from WaledRashed24/comics: direct link, hf CLI and curl.
- Browser
- Download file 599 Bytes
-
https://huggingface.co/spaces/WaledRashed24/comics/resolve/c1936bbfe4839bc9ca08d77d84e6d6e8010ee8a9/src/lib/parseBadJSON.ts
- Command line
-
hf download hf://spaces/WaledRashed24/comics@c1936bbfe4839bc9ca08d77d84e6d6e8010ee8a9/src/lib/parseBadJSON.ts
-
curl -L -o parseBadJSON.ts https://huggingface.co/spaces/WaledRashed24/comics/resolve/c1936bbfe4839bc9ca08d77d84e6d6e8010ee8a9/src/lib/parseBadJSON.ts
599 Bytes
| import { LLMResponse } from "@/types" | |
| export function parseBadJSON(jsonLikeString: string): LLMResponse { | |
| try { | |
| return JSON.parse(jsonLikeString) as LLMResponse | |
| } catch (err) { | |
| var regex = /\{\s*"panel":\s*(\d+),\s*"instructions"\s*:\s*"([^"]+)",\s*"caption":\s*"([^"]*)"\s*\}/gs; | |
| let results = []; | |
| let match; | |
| while ((match = regex.exec(jsonLikeString)) !== null) { | |
| let json = { | |
| panel: Number(match[1]), | |
| instructions: match[2], | |
| caption: match[3] | |
| }; | |
| results.push(json); | |
| } | |
| return results as LLMResponse | |
| } | |
| } |