Update handler.py
Browse files- handler.py +11 -1
handler.py
CHANGED
@@ -14,7 +14,7 @@ import numpy as np
|
|
14 |
import torch
|
15 |
from diffusers import LTXPipeline, LTXImageToVideoPipeline
|
16 |
from PIL import Image
|
17 |
-
|
18 |
from varnish import Varnish
|
19 |
|
20 |
# Configure logging
|
@@ -195,6 +195,10 @@ class GenerationConfig:
|
|
195 |
# it should look the same or nearly the same as the input but it isn't technically lossless.
|
196 |
# The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate.
|
197 |
quality: int = 18
|
|
|
|
|
|
|
|
|
198 |
|
199 |
def validate_and_adjust(self) -> 'GenerationConfig':
|
200 |
"""Validate and adjust parameters to meet constraints"""
|
@@ -347,6 +351,8 @@ class EndpointHandler:
|
|
347 |
- audio_prompt (optional, str): prompt to use for the audio generation (concepts to add)
|
348 |
- audio_negative_prompt (optional, str): nehative prompt to use for the audio generation (concepts to ignore)
|
349 |
- quality (optional, str, default to 18): The range of the CRF scale is 0–51, where 0 is lossless (for 8 bit only, for 10 bit use -qp 0), 23 is the default, and 51 is worst quality possible.
|
|
|
|
|
350 |
Returns:
|
351 |
Dictionary containing:
|
352 |
- video: Base64 encoded MP4 data URI
|
@@ -392,6 +398,10 @@ class EndpointHandler:
|
|
392 |
audio_prompt=params.get("audio_prompt", GenerationConfig.audio_prompt),
|
393 |
audio_negative_prompt=params.get("audio_negative_prompt", GenerationConfig.audio_negative_prompt),
|
394 |
quality=params.get("quality", GenerationConfig.quality),
|
|
|
|
|
|
|
|
|
395 |
).validate_and_adjust()
|
396 |
|
397 |
#logger.debug(f"Global request settings:")
|
|
|
14 |
import torch
|
15 |
from diffusers import LTXPipeline, LTXImageToVideoPipeline
|
16 |
from PIL import Image
|
17 |
+
from teacache import TeaCacheConfig, enable_teacache
|
18 |
from varnish import Varnish
|
19 |
|
20 |
# Configure logging
|
|
|
195 |
# it should look the same or nearly the same as the input but it isn't technically lossless.
|
196 |
# The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate.
|
197 |
quality: int = 18
|
198 |
+
|
199 |
+
# TeaCache settings
|
200 |
+
enable_teacache: bool = True
|
201 |
+
teacache_threshold: float = 0.15
|
202 |
|
203 |
def validate_and_adjust(self) -> 'GenerationConfig':
|
204 |
"""Validate and adjust parameters to meet constraints"""
|
|
|
351 |
- audio_prompt (optional, str): prompt to use for the audio generation (concepts to add)
|
352 |
- audio_negative_prompt (optional, str): nehative prompt to use for the audio generation (concepts to ignore)
|
353 |
- quality (optional, str, default to 18): The range of the CRF scale is 0–51, where 0 is lossless (for 8 bit only, for 10 bit use -qp 0), 23 is the default, and 51 is worst quality possible.
|
354 |
+
- enable_teacache (optional, bool, default to True): Generate faster at the cost of a slight quality loss
|
355 |
+
- teacache_threshold (optional, float, default to 0.15): Amount of cache
|
356 |
Returns:
|
357 |
Dictionary containing:
|
358 |
- video: Base64 encoded MP4 data URI
|
|
|
398 |
audio_prompt=params.get("audio_prompt", GenerationConfig.audio_prompt),
|
399 |
audio_negative_prompt=params.get("audio_negative_prompt", GenerationConfig.audio_negative_prompt),
|
400 |
quality=params.get("quality", GenerationConfig.quality),
|
401 |
+
|
402 |
+
# TeaCache settings
|
403 |
+
enable_teacache=params.get("enable_teacache", True),
|
404 |
+
teacache_threshold=params.get("teacache_threshold", 0.15)
|
405 |
).validate_and_adjust()
|
406 |
|
407 |
#logger.debug(f"Global request settings:")
|