Spaces:
Running on Zero
Running on Zero
Connect Arrow 2 text-to-animation
Browse files- generator.py +10 -1
generator.py
CHANGED
|
@@ -6,6 +6,7 @@ from urllib.error import HTTPError, URLError
|
|
| 6 |
from urllib.request import Request, urlopen
|
| 7 |
|
| 8 |
from motion import MOTIONS, add_motion
|
|
|
|
| 9 |
from validator import MAX_SVG_BYTES, SVGError, parse_svg, svg_text
|
| 10 |
|
| 11 |
DEFAULT_MODEL = "Qwen/Qwen3-Coder-30B-A3B-Instruct"
|
|
@@ -104,10 +105,13 @@ def _read_generated_svg(response: str) -> str:
|
|
| 104 |
return svg_text(parse_svg(match.group(), require_animation=True))
|
| 105 |
|
| 106 |
|
| 107 |
-
def generate_svg(
|
|
|
|
|
|
|
| 108 |
prompt = prompt.strip()
|
| 109 |
if not 0 < len(prompt) <= MAX_PROMPT_LENGTH:
|
| 110 |
raise GenerationError(f"์์ง์ ์ค๋ช
์ 1~{MAX_PROMPT_LENGTH}์๋ก ์
๋ ฅํด ์ฃผ์ธ์.")
|
|
|
|
| 111 |
if upload is not None:
|
| 112 |
if len(upload) > MAX_SVG_BYTES:
|
| 113 |
raise SVGError("SVG๋ 100 KB ์ดํ์ฌ์ผ ํฉ๋๋ค.")
|
|
@@ -115,6 +119,11 @@ def generate_svg(prompt: str, upload: bytes | None = None) -> str:
|
|
| 115 |
root = parse_svg(upload.decode("utf-8-sig"))
|
| 116 |
except UnicodeDecodeError as exc:
|
| 117 |
raise SVGError("UTF-8๋ก ์ ์ฅ๋ SVG๋ฅผ ์ฌ๋ ค ์ฃผ์ธ์.") from exc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
response = _complete(MOTION_PROMPT, prompt, max_tokens=180)
|
| 119 |
try:
|
| 120 |
match = re.search(r"\{[^{}]*\}", response)
|
|
|
|
| 6 |
from urllib.request import Request, urlopen
|
| 7 |
|
| 8 |
from motion import MOTIONS, add_motion
|
| 9 |
+
from quiver import generate_animation
|
| 10 |
from validator import MAX_SVG_BYTES, SVGError, parse_svg, svg_text
|
| 11 |
|
| 12 |
DEFAULT_MODEL = "Qwen/Qwen3-Coder-30B-A3B-Instruct"
|
|
|
|
| 105 |
return svg_text(parse_svg(match.group(), require_animation=True))
|
| 106 |
|
| 107 |
|
| 108 |
+
def generate_svg(
|
| 109 |
+
prompt: str, upload: bytes | None = None, *, quiver_key: str | None = None,
|
| 110 |
+
) -> str:
|
| 111 |
prompt = prompt.strip()
|
| 112 |
if not 0 < len(prompt) <= MAX_PROMPT_LENGTH:
|
| 113 |
raise GenerationError(f"์์ง์ ์ค๋ช
์ 1~{MAX_PROMPT_LENGTH}์๋ก ์
๋ ฅํด ์ฃผ์ธ์.")
|
| 114 |
+
root = None
|
| 115 |
if upload is not None:
|
| 116 |
if len(upload) > MAX_SVG_BYTES:
|
| 117 |
raise SVGError("SVG๋ 100 KB ์ดํ์ฌ์ผ ํฉ๋๋ค.")
|
|
|
|
| 119 |
root = parse_svg(upload.decode("utf-8-sig"))
|
| 120 |
except UnicodeDecodeError as exc:
|
| 121 |
raise SVGError("UTF-8๋ก ์ ์ฅ๋ SVG๋ฅผ ์ฌ๋ ค ์ฃผ์ธ์.") from exc
|
| 122 |
+
|
| 123 |
+
if quiver_key is not None:
|
| 124 |
+
return generate_animation(prompt, quiver_key, svg_text(root) if root is not None else None)
|
| 125 |
+
|
| 126 |
+
if root is not None:
|
| 127 |
response = _complete(MOTION_PROMPT, prompt, max_tokens=180)
|
| 128 |
try:
|
| 129 |
match = re.search(r"\{[^{}]*\}", response)
|