Update handler.py
Browse files- handler.py +10 -9
handler.py
CHANGED
|
@@ -169,24 +169,24 @@ class EndpointHandler:
|
|
| 169 |
- metadata: Dictionary with actual values used for generation
|
| 170 |
"""
|
| 171 |
# Get inputs from request data
|
| 172 |
-
prompt = data.
|
| 173 |
if not prompt:
|
| 174 |
raise ValueError("No prompt provided in the 'inputs' field")
|
| 175 |
|
| 176 |
# Get and validate resolution
|
| 177 |
-
width = data.
|
| 178 |
-
height = data.
|
| 179 |
width, height = self._validate_and_adjust_resolution(width, height)
|
| 180 |
|
| 181 |
# Get and validate frames and FPS
|
| 182 |
-
num_frames = data.
|
| 183 |
-
fps = data.
|
| 184 |
num_frames, fps = self._validate_and_adjust_frames(num_frames, fps)
|
| 185 |
|
| 186 |
# Get other parameters with defaults
|
| 187 |
-
guidance_scale = data.
|
| 188 |
-
num_inference_steps = data.
|
| 189 |
-
seed = data.
|
| 190 |
seed = None if seed == -1 else int(seed)
|
| 191 |
|
| 192 |
logger.info(f"Generating video with prompt: '{prompt}'")
|
|
@@ -208,7 +208,8 @@ class EndpointHandler:
|
|
| 208 |
# Check if image is provided for image-to-video generation
|
| 209 |
image_data = data.get("image")
|
| 210 |
if image_data:
|
| 211 |
-
|
|
|
|
| 212 |
image_bytes = base64.b64decode(image_data)
|
| 213 |
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 214 |
logger.info("Using image-to-video generation mode")
|
|
|
|
| 169 |
- metadata: Dictionary with actual values used for generation
|
| 170 |
"""
|
| 171 |
# Get inputs from request data
|
| 172 |
+
prompt = data.get("inputs", None)
|
| 173 |
if not prompt:
|
| 174 |
raise ValueError("No prompt provided in the 'inputs' field")
|
| 175 |
|
| 176 |
# Get and validate resolution
|
| 177 |
+
width = data.get("width", self.DEFAULT_WIDTH)
|
| 178 |
+
height = data.get("height", self.DEFAULT_HEIGHT)
|
| 179 |
width, height = self._validate_and_adjust_resolution(width, height)
|
| 180 |
|
| 181 |
# Get and validate frames and FPS
|
| 182 |
+
num_frames = data.get("num_frames", self.DEFAULT_NUM_FRAMES)
|
| 183 |
+
fps = data.get("fps", self.DEFAULT_FPS)
|
| 184 |
num_frames, fps = self._validate_and_adjust_frames(num_frames, fps)
|
| 185 |
|
| 186 |
# Get other parameters with defaults
|
| 187 |
+
guidance_scale = data.get("guidance_scale", 7.5)
|
| 188 |
+
num_inference_steps = data.get("num_inference_steps", self.DEFAULT_NUM_STEPS)
|
| 189 |
+
seed = data.get("seed", -1)
|
| 190 |
seed = None if seed == -1 else int(seed)
|
| 191 |
|
| 192 |
logger.info(f"Generating video with prompt: '{prompt}'")
|
|
|
|
| 208 |
# Check if image is provided for image-to-video generation
|
| 209 |
image_data = data.get("image")
|
| 210 |
if image_data:
|
| 211 |
+
if image_data.startswith('data:'):
|
| 212 |
+
image_data = image_data.split(',', 1)[1]
|
| 213 |
image_bytes = base64.b64decode(image_data)
|
| 214 |
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 215 |
logger.info("Using image-to-video generation mode")
|