Commit
•
9840797
1
Parent(s):
f6dd4f3
Update handler.py
Browse files- handler.py +17 -1
handler.py
CHANGED
@@ -164,6 +164,22 @@ class EndpointHandler:
|
|
164 |
|
165 |
return video_data_uri, metadata
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
168 |
"""Process the input data and generate video using LTX.
|
169 |
|
@@ -238,7 +254,7 @@ class EndpointHandler:
|
|
238 |
frames = self.text_to_video(**generation_kwargs).frames
|
239 |
|
240 |
# Process and encode video
|
241 |
-
video_data_uri, metadata =
|
242 |
frames=frames,
|
243 |
fps=fps,
|
244 |
upscale_factor=upscale_factor,
|
|
|
164 |
|
165 |
return video_data_uri, metadata
|
166 |
|
167 |
+
def _run_async(self, frames: torch.Tensor, fps: int, upscale_factor: int, enable_interpolation: bool, interpolation_exp: int) -> Dict[str, Any]:
|
168 |
+
"""Run asynchronous video processing in a synchronous context"""
|
169 |
+
loop = asyncio.new_event_loop()
|
170 |
+
try:
|
171 |
+
return loop.run_until_complete(
|
172 |
+
self.process_and_encode_video(
|
173 |
+
frames=frames,
|
174 |
+
fps=fps,
|
175 |
+
upscale_factor=upscale_factor,
|
176 |
+
enable_interpolation=enable_interpolation,
|
177 |
+
interpolation_exp=interpolation_exp
|
178 |
+
)
|
179 |
+
)
|
180 |
+
finally:
|
181 |
+
loop.close()
|
182 |
+
|
183 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
184 |
"""Process the input data and generate video using LTX.
|
185 |
|
|
|
254 |
frames = self.text_to_video(**generation_kwargs).frames
|
255 |
|
256 |
# Process and encode video
|
257 |
+
video_data_uri, metadata = self._run_async(
|
258 |
frames=frames,
|
259 |
fps=fps,
|
260 |
upscale_factor=upscale_factor,
|