Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,10 @@ import uuid
|
|
5 |
import logging
|
6 |
import importlib.util
|
7 |
import numpy as np
|
8 |
-
import requests
|
9 |
from diffusers import AnimateDiffPipeline, EulerDiscreteScheduler
|
10 |
from diffusers.utils import export_to_video
|
11 |
from huggingface_hub import hf_hub_download
|
12 |
from safetensors.torch import load_file
|
13 |
-
from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type
|
14 |
|
15 |
# Thiết lập logging
|
16 |
logging.basicConfig(level=logging.INFO)
|
@@ -52,18 +50,6 @@ pipe.scheduler = EulerDiscreteScheduler.from_config(
|
|
52 |
)
|
53 |
pipe.safety_checker = None
|
54 |
|
55 |
-
# Hàm tải lên Filebin với retry
|
56 |
-
@retry(
|
57 |
-
stop=stop_after_attempt(3), # Thử lại 3 lần
|
58 |
-
wait=wait_fixed(2), # Chờ 2 giây giữa các lần thử
|
59 |
-
retry=retry_if_exception_type(requests.exceptions.RequestException) # Thử lại nếu gặp lỗi mạng
|
60 |
-
)
|
61 |
-
def upload_to_filebin(file_path, file_name):
|
62 |
-
with open(file_path, "rb") as f:
|
63 |
-
response = requests.post(f"https://filebin.net/{uuid.uuid4()}/{file_name}", files={"file": (file_name, f)})
|
64 |
-
response.raise_for_status()
|
65 |
-
return response.json().get("url") # Lấy URL công khai từ phản hồi JSON
|
66 |
-
|
67 |
# Hàm tạo video
|
68 |
def generate_image(prompt, base="Realistic", motion="", step=1, progress=gr.Progress()):
|
69 |
global step_loaded, base_loaded, motion_loaded
|
@@ -134,15 +120,8 @@ def generate_image(prompt, base="Realistic", motion="", step=1, progress=gr.Prog
|
|
134 |
|
135 |
logger.info(f"✅ Video sẵn sàng tại {video_path}")
|
136 |
|
137 |
-
#
|
138 |
-
|
139 |
-
public_url = upload_to_filebin(video_path, f"{name}.mp4")
|
140 |
-
logger.info(f"✅ Public URL: {public_url}")
|
141 |
-
return public_url # Trả về URL công khai
|
142 |
-
except Exception as e:
|
143 |
-
logger.error(f"❌ Không thể tải lên Filebin: {e}")
|
144 |
-
# Fallback: Trả về đường dẫn tệp để Gradio hiển thị
|
145 |
-
return video_path
|
146 |
|
147 |
except Exception as e:
|
148 |
logger.error(f"❌ Lỗi khi tạo video: {e}")
|
|
|
5 |
import logging
|
6 |
import importlib.util
|
7 |
import numpy as np
|
|
|
8 |
from diffusers import AnimateDiffPipeline, EulerDiscreteScheduler
|
9 |
from diffusers.utils import export_to_video
|
10 |
from huggingface_hub import hf_hub_download
|
11 |
from safetensors.torch import load_file
|
|
|
12 |
|
13 |
# Thiết lập logging
|
14 |
logging.basicConfig(level=logging.INFO)
|
|
|
50 |
)
|
51 |
pipe.safety_checker = None
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
# Hàm tạo video
|
54 |
def generate_image(prompt, base="Realistic", motion="", step=1, progress=gr.Progress()):
|
55 |
global step_loaded, base_loaded, motion_loaded
|
|
|
120 |
|
121 |
logger.info(f"✅ Video sẵn sàng tại {video_path}")
|
122 |
|
123 |
+
# Trả về gr.File để Gradio tạo URL công khai
|
124 |
+
return gr.File(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
except Exception as e:
|
127 |
logger.error(f"❌ Lỗi khi tạo video: {e}")
|