Update Modules/Generate_Video.py
Browse files
Modules/Generate_Video.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import os
|
|
|
|
| 4 |
import random
|
| 5 |
import tempfile
|
| 6 |
from typing import Annotated
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
from huggingface_hub import InferenceClient
|
|
|
|
| 10 |
|
| 11 |
from app import _log_call_end, _log_call_start, _truncate_for_log
|
| 12 |
from ._docstrings import autodoc
|
|
@@ -22,9 +24,10 @@ TOOL_SUMMARY = (
|
|
| 22 |
|
| 23 |
|
| 24 |
def _write_video_tmp(data_iter_or_bytes: object, suffix: str = ".mp4") -> str:
|
| 25 |
-
|
|
|
|
| 26 |
try:
|
| 27 |
-
with
|
| 28 |
if isinstance(data_iter_or_bytes, (bytes, bytearray)):
|
| 29 |
file.write(data_iter_or_bytes)
|
| 30 |
elif hasattr(data_iter_or_bytes, "read"):
|
|
@@ -39,11 +42,11 @@ def _write_video_tmp(data_iter_or_bytes: object, suffix: str = ".mp4") -> str:
|
|
| 39 |
raise gr.Error("Unsupported video data type returned by provider.")
|
| 40 |
except Exception:
|
| 41 |
try:
|
| 42 |
-
os.remove(
|
| 43 |
except Exception:
|
| 44 |
pass
|
| 45 |
raise
|
| 46 |
-
return
|
| 47 |
|
| 48 |
|
| 49 |
@autodoc(
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import os
|
| 4 |
+
import uuid
|
| 5 |
import random
|
| 6 |
import tempfile
|
| 7 |
from typing import Annotated
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
from huggingface_hub import InferenceClient
|
| 11 |
+
from .File_System import ROOT_DIR
|
| 12 |
|
| 13 |
from app import _log_call_end, _log_call_start, _truncate_for_log
|
| 14 |
from ._docstrings import autodoc
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
def _write_video_tmp(data_iter_or_bytes: object, suffix: str = ".mp4") -> str:
|
| 27 |
+
filename = f"video_{uuid.uuid4().hex[:8]}{suffix}"
|
| 28 |
+
path = os.path.join(ROOT_DIR, filename)
|
| 29 |
try:
|
| 30 |
+
with open(path, "wb") as file:
|
| 31 |
if isinstance(data_iter_or_bytes, (bytes, bytearray)):
|
| 32 |
file.write(data_iter_or_bytes)
|
| 33 |
elif hasattr(data_iter_or_bytes, "read"):
|
|
|
|
| 42 |
raise gr.Error("Unsupported video data type returned by provider.")
|
| 43 |
except Exception:
|
| 44 |
try:
|
| 45 |
+
os.remove(path)
|
| 46 |
except Exception:
|
| 47 |
pass
|
| 48 |
raise
|
| 49 |
+
return path
|
| 50 |
|
| 51 |
|
| 52 |
@autodoc(
|