Spaces:
Sleeping
Sleeping
Download src/lib/parseDraw.ts from SeeMoon1/Mutsu-Studio-Cloud: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/SeeMoon1/Mutsu-Studio-Cloud/resolve/main/src/lib/parseDraw.ts
- Command line
-
hf download hf://spaces/SeeMoon1/Mutsu-Studio-Cloud/src/lib/parseDraw.ts
-
curl -L -o parseDraw.ts https://huggingface.co/spaces/SeeMoon1/Mutsu-Studio-Cloud/resolve/main/src/lib/parseDraw.ts
1.96 kB
| export type DrawCommand = { | |
| trigger: boolean; | |
| type?: 'image' | 'video'; | |
| description: string; | |
| negativePrompt: string; | |
| charId?: string; | |
| outfitId?: string; | |
| videoModel?: string; | |
| parameters?: any; | |
| }; | |
| export const cleanDrawTag = (content: string) => { | |
| return content | |
| .replace(/<draw>[\s\S]*?<\/draw>/g, "") | |
| .replace(/<draw_log>[\s\S]*?<\/draw_log>/g, "") | |
| .replace(/<video>[\s\S]*?<\/video>/g, "") | |
| .replace(/<video_log>[\s\S]*?<\/video_log>/g, "") | |
| .trim(); | |
| }; | |
| export const parseMediaTag = (content: string): DrawCommand | null => { | |
| const videoMatch = content.match(/<video>([\s\S]*?)<\/video>/); | |
| if (videoMatch) return parseInnerJson(videoMatch[1], 'video'); | |
| const drawMatch = content.match(/<draw>([\s\S]*?)<\/draw>/); | |
| if (drawMatch) return parseInnerJson(drawMatch[1], 'image'); | |
| return null; | |
| }; | |
| const parseInnerJson = (rawContent: string, type: 'image' | 'video'): DrawCommand | null => { | |
| try { | |
| const jsonString = rawContent.replace(/```json/g, "").replace(/```/g, "").trim(); | |
| const data = JSON.parse(jsonString); | |
| const desc = data.description || data.prompt || ""; | |
| let rawCharId = data.charId || data.character || data.id; | |
| if (Array.isArray(rawCharId)) rawCharId = rawCharId[0]; | |
| return { | |
| trigger: true, | |
| type: type, | |
| description: desc, | |
| charId: rawCharId, | |
| outfitId: data.outfitId || "casual", | |
| videoModel: data.model, | |
| parameters: data.parameters || {}, | |
| negativePrompt: data.negativePrompt || data.neg || "" | |
| }; | |
| } catch (e) { | |
| return { | |
| trigger: true, | |
| type: type, | |
| description: rawContent, | |
| parameters: {}, | |
| negativePrompt: "", | |
| outfitId: "casual" | |
| }; | |
| } | |
| } | |
| export const parseDrawTag = parseMediaTag; |