Kimodo Bot commited on
Commit
2d7ce22
·
1 Parent(s): 075f5be

Add spaces GPU-decorated execution handler

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -8,6 +8,19 @@ from typing import Any
8
 
9
  import gradio as gr
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def _parse_character_ids(raw: str, count: int) -> list[str]:
13
  items = [part.strip() for part in (raw or "").split(",") if part.strip()]
@@ -56,7 +69,8 @@ def plan_script(scene_id: str, prompt: str, characters: int, character_ids_raw:
56
  return json.dumps(payload, indent=2)
57
 
58
 
59
- def execute_scene(script_json: str, fps: int, seed: int) -> tuple[str, dict[str, Any], str]:
 
60
  if not script_json.strip():
61
  return "", {"timeline": []}, "Execution failed: no script"
62
 
@@ -85,6 +99,10 @@ def execute_scene(script_json: str, fps: int, seed: int) -> tuple[str, dict[str,
85
  return json.dumps(summary, indent=2), {"timeline": timeline}, status
86
 
87
 
 
 
 
 
88
  def render_frame(frame_idx: int, playback_state: dict[str, Any]) -> str:
89
  timeline = playback_state.get("timeline") or []
90
  if not timeline:
 
8
 
9
  import gradio as gr
10
 
11
+ try:
12
+ import spaces # type: ignore
13
+ except Exception: # pragma: no cover
14
+ class _SpacesFallback:
15
+ @staticmethod
16
+ def GPU(*args, **kwargs):
17
+ def _decorator(fn):
18
+ return fn
19
+
20
+ return _decorator
21
+
22
+ spaces = _SpacesFallback()
23
+
24
 
25
  def _parse_character_ids(raw: str, count: int) -> list[str]:
26
  items = [part.strip() for part in (raw or "").split(",") if part.strip()]
 
69
  return json.dumps(payload, indent=2)
70
 
71
 
72
+ @spaces.GPU(duration=60)
73
+ def _execute_scene_gpu(script_json: str, fps: int, seed: int) -> tuple[str, dict[str, Any], str]:
74
  if not script_json.strip():
75
  return "", {"timeline": []}, "Execution failed: no script"
76
 
 
99
  return json.dumps(summary, indent=2), {"timeline": timeline}, status
100
 
101
 
102
+ def execute_scene(script_json: str, fps: int, seed: int) -> tuple[str, dict[str, Any], str]:
103
+ return _execute_scene_gpu(script_json, fps, seed)
104
+
105
+
106
  def render_frame(frame_idx: int, playback_state: dict[str, Any]) -> str:
107
  timeline = playback_state.get("timeline") or []
108
  if not timeline: