VirtualOasis commited on
Commit
042d9ad
·
verified ·
1 Parent(s): 37caa62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -7,6 +7,11 @@ import gradio as gr
7
  from cinegen import CharacterDesigner, StoryGenerator, VideoDirector
8
  from cinegen.models import Storyboard
9
 
 
 
 
 
 
10
  STYLE_CHOICES = [
11
  "Cinematic Realism",
12
  "Neo-Noir Animation",
@@ -26,6 +31,15 @@ SCENE_COLUMNS = ["Scene", "Title", "Action", "Visuals", "Characters", "Duration
26
  CHARACTER_COLUMNS = ["ID", "Name", "Role", "Traits"]
27
 
28
 
 
 
 
 
 
 
 
 
 
29
  def _character_dropdown_update(board: Storyboard | None):
30
  if not board or not board.characters:
31
  return gr.update(choices=[], value=None, interactive=False)
@@ -114,6 +128,7 @@ def handle_character_regen(
114
  return gallery, updated_board
115
 
116
 
 
117
  def handle_video_render(
118
  storyboard: Storyboard | None,
119
  hf_token: str,
 
7
  from cinegen import CharacterDesigner, StoryGenerator, VideoDirector
8
  from cinegen.models import Storyboard
9
 
10
+ try: # pragma: no cover - spaces is only available inside HF Spaces
11
+ import spaces # type: ignore
12
+ except Exception: # pragma: no cover - keep local dev working without spaces pkg
13
+ spaces = None # type: ignore
14
+
15
  STYLE_CHOICES = [
16
  "Cinematic Realism",
17
  "Neo-Noir Animation",
 
31
  CHARACTER_COLUMNS = ["ID", "Name", "Role", "Traits"]
32
 
33
 
34
+ def gpu_guard(duration: int = 120):
35
+ def decorator(fn):
36
+ if not spaces:
37
+ return fn
38
+ return spaces.GPU(duration=duration)(fn)
39
+
40
+ return decorator
41
+
42
+
43
  def _character_dropdown_update(board: Storyboard | None):
44
  if not board or not board.characters:
45
  return gr.update(choices=[], value=None, interactive=False)
 
128
  return gallery, updated_board
129
 
130
 
131
+ @gpu_guard(duration=300)
132
  def handle_video_render(
133
  storyboard: Storyboard | None,
134
  hf_token: str,