Maximofn commited on
Commit
512f6a4
·
1 Parent(s): a203df4

Add prompt prefix handling and update example generation parameters

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -14,6 +14,31 @@ TRANSFORMER_MODELS = [
14
  "finetrainers/cakeify-v0"
15
  ]
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def load_models(transformer_model):
18
  """Load transformer and pipeline models"""
19
  # Load the selected transformer model
@@ -40,7 +65,7 @@ def save_video(video_frames, fps=25):
40
  export_to_video(video_frames, tmp_file.name, fps=fps)
41
  return tmp_file.name
42
 
43
- @spaces.GPU
44
  def generate_video_pipeline(pipeline, prompt, negative_prompt, num_frames, height, width, num_inference_steps):
45
  """Generate video using the pipeline"""
46
  # Move to appropriate device
@@ -64,6 +89,11 @@ def generate_video_pipeline(pipeline, prompt, negative_prompt, num_frames, heigh
64
 
65
  def generate_video(transformer_model, prompt, negative_prompt, num_frames, height, width, num_inference_steps):
66
  """Main function to handle the video generation process"""
 
 
 
 
 
67
  # Load models
68
  pipeline = load_models(transformer_model)
69
 
@@ -153,25 +183,25 @@ def create_interface():
153
  "sayakpaul/pika-dissolve-v0",
154
  "PIKA_DISSOLVE A slender glass vase, brimming with tiny white pebbles, stands centered on a polished ebony dais. Without warning, the glass begins to dissolve from the edges inward. Wisps of translucent dust swirl upward in an elegant spiral, illuminating each pebble as they drop onto the dais. The gently drifting dust eventually settles, leaving only the scattered stones and faint traces of shimmering powder on the stage.",
155
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
156
- 8, 32, 32, 10
157
  ],
158
  [
159
  "finetrainers/crush-smol-v0",
160
  "DIFF_crush A thick burger is placed on a dining table, and a large metal cylinder descends from above, crushing the burger as if it were under a hydraulic press. The bulb is crushed, leaving a pile of debris around it.",
161
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
162
- 8, 32, 32, 10
163
  ],
164
  [
165
  "finetrainers/3dgs-v0",
166
  "3D_dissolve In a 3D appearance, a bookshelf filled with books is surrounded by a burst of red sparks, creating a dramatic and explosive effect against a black background.",
167
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
168
- 8, 32, 32, 10
169
  ],
170
  [
171
  "finetrainers/cakeify-v0",
172
  "PIKA_CAKEIFY On a gleaming glass display stand, a sleek black purse quietly commands attention. Suddenly, a knife appears and slices through the shoe, revealing a fluffy vanilla sponge at its core. Immediately, it turns into a hyper-realistic prop cake, delighting the senses with its playful juxtaposition of the everyday and the extraordinary.",
173
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
174
- 8, 32, 32, 10
175
  ]
176
  ],
177
  inputs=[
 
14
  "finetrainers/cakeify-v0"
15
  ]
16
 
17
+ # Model prefix mapping
18
+ MODEL_PREFIXES = {
19
+ "sayakpaul/pika-dissolve-v0": "PIKA_DISSOLVE",
20
+ "finetrainers/crush-smol-v0": "DIFF_crush",
21
+ "finetrainers/3dgs-v0": "3D_dissolve",
22
+ "finetrainers/cakeify-v0": "PIKA_CAKEIFY"
23
+ }
24
+
25
+ def check_and_fix_prompt(transformer_model, prompt):
26
+ """Check and fix prompt according to model requirements"""
27
+ required_prefix = MODEL_PREFIXES.get(transformer_model)
28
+ if not required_prefix:
29
+ print(f"No required prefix found for model: {transformer_model}")
30
+ return prompt
31
+
32
+ # Remove leading/trailing whitespace
33
+ prompt = prompt.strip()
34
+
35
+ # Check if prompt already starts with the required prefix
36
+ if not prompt.startswith(required_prefix):
37
+ print(f"Adding required prefix '{required_prefix}' to prompt")
38
+ prompt = f"{required_prefix} {prompt}"
39
+
40
+ return prompt
41
+
42
  def load_models(transformer_model):
43
  """Load transformer and pipeline models"""
44
  # Load the selected transformer model
 
65
  export_to_video(video_frames, tmp_file.name, fps=fps)
66
  return tmp_file.name
67
 
68
+ @spaces.GPU(duration=1000)
69
  def generate_video_pipeline(pipeline, prompt, negative_prompt, num_frames, height, width, num_inference_steps):
70
  """Generate video using the pipeline"""
71
  # Move to appropriate device
 
89
 
90
  def generate_video(transformer_model, prompt, negative_prompt, num_frames, height, width, num_inference_steps):
91
  """Main function to handle the video generation process"""
92
+ # Check and fix prompt
93
+ print(f"Original prompt: {prompt}")
94
+ prompt = check_and_fix_prompt(transformer_model, prompt)
95
+ print(f"Final prompt: {prompt}")
96
+
97
  # Load models
98
  pipeline = load_models(transformer_model)
99
 
 
183
  "sayakpaul/pika-dissolve-v0",
184
  "PIKA_DISSOLVE A slender glass vase, brimming with tiny white pebbles, stands centered on a polished ebony dais. Without warning, the glass begins to dissolve from the edges inward. Wisps of translucent dust swirl upward in an elegant spiral, illuminating each pebble as they drop onto the dais. The gently drifting dust eventually settles, leaving only the scattered stones and faint traces of shimmering powder on the stage.",
185
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
186
+ 50, 224, 224, 50
187
  ],
188
  [
189
  "finetrainers/crush-smol-v0",
190
  "DIFF_crush A thick burger is placed on a dining table, and a large metal cylinder descends from above, crushing the burger as if it were under a hydraulic press. The bulb is crushed, leaving a pile of debris around it.",
191
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
192
+ 50, 224, 224, 50
193
  ],
194
  [
195
  "finetrainers/3dgs-v0",
196
  "3D_dissolve In a 3D appearance, a bookshelf filled with books is surrounded by a burst of red sparks, creating a dramatic and explosive effect against a black background.",
197
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
198
+ 50, 224, 224, 50
199
  ],
200
  [
201
  "finetrainers/cakeify-v0",
202
  "PIKA_CAKEIFY On a gleaming glass display stand, a sleek black purse quietly commands attention. Suddenly, a knife appears and slices through the shoe, revealing a fluffy vanilla sponge at its core. Immediately, it turns into a hyper-realistic prop cake, delighting the senses with its playful juxtaposition of the everyday and the extraordinary.",
203
  "inconsistent motion, blurry motion, worse quality, degenerate outputs, deformed outputs",
204
+ 50, 224, 224, 50
205
  ]
206
  ],
207
  inputs=[