add debug info
Browse files- oss_utils.py +26 -2
- simulation.py +32 -6
oss_utils.py
CHANGED
@@ -13,9 +13,21 @@ OSS_CONFIG = {
|
|
13 |
"bucket_name": os.getenv("OSS_BUCKET_NAME")
|
14 |
}
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# 初始化OSS客户端
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# 临时文件根目录
|
21 |
TMP_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tmp")
|
@@ -23,6 +35,10 @@ os.makedirs(TMP_ROOT, exist_ok=True)
|
|
23 |
|
24 |
def list_oss_files(folder_path: str) -> List[str]:
|
25 |
"""列出OSS文件夹中的所有文件"""
|
|
|
|
|
|
|
|
|
26 |
files = []
|
27 |
try:
|
28 |
print(f"🔍 OSS DEBUG: Listing files with prefix: '{folder_path}'")
|
@@ -44,6 +60,10 @@ def list_oss_files(folder_path: str) -> List[str]:
|
|
44 |
|
45 |
def download_oss_file(oss_path: str, local_path: str):
|
46 |
"""从OSS下载文件到本地"""
|
|
|
|
|
|
|
|
|
47 |
try:
|
48 |
# 确保本地目录存在
|
49 |
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
@@ -54,6 +74,10 @@ def download_oss_file(oss_path: str, local_path: str):
|
|
54 |
|
55 |
def oss_file_exists(oss_path: str) -> bool:
|
56 |
"""检查OSS文件是否存在"""
|
|
|
|
|
|
|
|
|
57 |
try:
|
58 |
return bucket.object_exists(oss_path)
|
59 |
except Exception as e:
|
|
|
13 |
"bucket_name": os.getenv("OSS_BUCKET_NAME")
|
14 |
}
|
15 |
|
16 |
+
# 调试OSS配置信息
|
17 |
+
print(f"🔍 OSS CONFIG DEBUG:")
|
18 |
+
print(f" - access_key_id: {'✅' if OSS_CONFIG['access_key_id'] else '❌'} ({'***' + OSS_CONFIG['access_key_id'][-4:] if OSS_CONFIG['access_key_id'] else 'None'})")
|
19 |
+
print(f" - access_key_secret: {'✅' if OSS_CONFIG['access_key_secret'] else '❌'} ({'***' + OSS_CONFIG['access_key_secret'][-4:] if OSS_CONFIG['access_key_secret'] else 'None'})")
|
20 |
+
print(f" - endpoint: {OSS_CONFIG['endpoint'] or '❌ None'}")
|
21 |
+
print(f" - bucket_name: {OSS_CONFIG['bucket_name'] or '❌ None'}")
|
22 |
+
|
23 |
# 初始化OSS客户端
|
24 |
+
try:
|
25 |
+
auth = oss2.Auth(OSS_CONFIG["access_key_id"], OSS_CONFIG["access_key_secret"])
|
26 |
+
bucket = oss2.Bucket(auth, OSS_CONFIG["endpoint"], OSS_CONFIG["bucket_name"])
|
27 |
+
print(f"✅ OSS client initialized successfully")
|
28 |
+
except Exception as e:
|
29 |
+
print(f"❌ OSS client initialization failed: {e}")
|
30 |
+
bucket = None
|
31 |
|
32 |
# 临时文件根目录
|
33 |
TMP_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tmp")
|
|
|
35 |
|
36 |
def list_oss_files(folder_path: str) -> List[str]:
|
37 |
"""列出OSS文件夹中的所有文件"""
|
38 |
+
if bucket is None:
|
39 |
+
print(f"❌ OSS DEBUG: Bucket not initialized, cannot list files")
|
40 |
+
return []
|
41 |
+
|
42 |
files = []
|
43 |
try:
|
44 |
print(f"🔍 OSS DEBUG: Listing files with prefix: '{folder_path}'")
|
|
|
60 |
|
61 |
def download_oss_file(oss_path: str, local_path: str):
|
62 |
"""从OSS下载文件到本地"""
|
63 |
+
if bucket is None:
|
64 |
+
print(f"❌ OSS DEBUG: Bucket not initialized, cannot download file")
|
65 |
+
raise Exception("OSS bucket not initialized")
|
66 |
+
|
67 |
try:
|
68 |
# 确保本地目录存在
|
69 |
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
|
|
74 |
|
75 |
def oss_file_exists(oss_path: str) -> bool:
|
76 |
"""检查OSS文件是否存在"""
|
77 |
+
if bucket is None:
|
78 |
+
print(f"❌ OSS DEBUG: Bucket not initialized, cannot check file existence")
|
79 |
+
return False
|
80 |
+
|
81 |
try:
|
82 |
return bucket.object_exists(oss_path)
|
83 |
except Exception as e:
|
simulation.py
CHANGED
@@ -198,14 +198,22 @@ def create_final_video_from_oss_images(result_folder: str, task_id: str, request
|
|
198 |
返回:
|
199 |
最终视频文件路径
|
200 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
# 获取图片文件夹路径
|
202 |
-
image_folder = os.path.join(
|
203 |
user_dir = get_user_tmp_dir(request.session_hash)
|
204 |
local_image_dir = os.path.join(user_dir, task_id, "final_images")
|
205 |
os.makedirs(local_image_dir, exist_ok=True)
|
206 |
|
207 |
# 添加调试信息
|
208 |
-
print(f"🔍 DEBUG: result_folder = {result_folder}")
|
|
|
209 |
print(f"🔍 DEBUG: task_id = {task_id}")
|
210 |
print(f"🔍 DEBUG: image_folder = {image_folder}")
|
211 |
print(f"🔍 DEBUG: user_dir = {user_dir}")
|
@@ -223,9 +231,9 @@ def create_final_video_from_oss_images(result_folder: str, task_id: str, request
|
|
223 |
print(f"🔍 DEBUG: First 5 image files: {image_files[:5]}")
|
224 |
|
225 |
if not image_files:
|
226 |
-
# 如果没有找到图片,尝试直接在
|
227 |
-
print(f"🔍 DEBUG: No images in {image_folder}, trying {
|
228 |
-
oss_files_direct = list_oss_files(
|
229 |
print(f"🔍 DEBUG: Files in result_folder: {len(oss_files_direct)}")
|
230 |
print(f"🔍 DEBUG: Direct files: {oss_files_direct[:10]}")
|
231 |
|
@@ -233,9 +241,27 @@ def create_final_video_from_oss_images(result_folder: str, task_id: str, request
|
|
233 |
all_image_files = [f for f in oss_files_direct if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
234 |
print(f"🔍 DEBUG: All image files in result_folder: {len(all_image_files)}")
|
235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
if all_image_files:
|
237 |
image_files = all_image_files
|
238 |
-
print(f"🔍 DEBUG: Using image files from
|
239 |
else:
|
240 |
raise gr.Error("No images found in OSS for final video creation")
|
241 |
|
|
|
198 |
返回:
|
199 |
最终视频文件路径
|
200 |
"""
|
201 |
+
# 清理result_folder路径,移除OSS前缀
|
202 |
+
cleaned_result_folder = result_folder.strip('/')
|
203 |
+
if cleaned_result_folder.startswith('oss-waic/'):
|
204 |
+
cleaned_result_folder = cleaned_result_folder[9:] # 移除 'oss-waic/' 前缀
|
205 |
+
elif cleaned_result_folder.startswith('/oss-waic/'):
|
206 |
+
cleaned_result_folder = cleaned_result_folder[10:] # 移除 '/oss-waic/' 前缀
|
207 |
+
|
208 |
# 获取图片文件夹路径
|
209 |
+
image_folder = os.path.join(cleaned_result_folder, "images").replace('\\', '/')
|
210 |
user_dir = get_user_tmp_dir(request.session_hash)
|
211 |
local_image_dir = os.path.join(user_dir, task_id, "final_images")
|
212 |
os.makedirs(local_image_dir, exist_ok=True)
|
213 |
|
214 |
# 添加调试信息
|
215 |
+
print(f"🔍 DEBUG: original result_folder = {result_folder}")
|
216 |
+
print(f"🔍 DEBUG: cleaned_result_folder = {cleaned_result_folder}")
|
217 |
print(f"🔍 DEBUG: task_id = {task_id}")
|
218 |
print(f"🔍 DEBUG: image_folder = {image_folder}")
|
219 |
print(f"🔍 DEBUG: user_dir = {user_dir}")
|
|
|
231 |
print(f"🔍 DEBUG: First 5 image files: {image_files[:5]}")
|
232 |
|
233 |
if not image_files:
|
234 |
+
# 如果没有找到图片,尝试直接在cleaned_result_folder中查找
|
235 |
+
print(f"🔍 DEBUG: No images in {image_folder}, trying {cleaned_result_folder}")
|
236 |
+
oss_files_direct = list_oss_files(cleaned_result_folder)
|
237 |
print(f"🔍 DEBUG: Files in result_folder: {len(oss_files_direct)}")
|
238 |
print(f"🔍 DEBUG: Direct files: {oss_files_direct[:10]}")
|
239 |
|
|
|
241 |
all_image_files = [f for f in oss_files_direct if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
242 |
print(f"🔍 DEBUG: All image files in result_folder: {len(all_image_files)}")
|
243 |
|
244 |
+
# 尝试不同的路径组合
|
245 |
+
alternative_paths = [
|
246 |
+
f"gradio_demo/tasks/{task_id}/images",
|
247 |
+
f"gradio_demo/tasks/{task_id}",
|
248 |
+
f"tasks/{task_id}/images",
|
249 |
+
f"tasks/{task_id}"
|
250 |
+
]
|
251 |
+
|
252 |
+
for alt_path in alternative_paths:
|
253 |
+
print(f"🔍 DEBUG: Trying alternative path: {alt_path}")
|
254 |
+
alt_files = list_oss_files(alt_path)
|
255 |
+
alt_images = [f for f in alt_files if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
256 |
+
print(f"🔍 DEBUG: Found {len(alt_images)} images in {alt_path}")
|
257 |
+
if alt_images:
|
258 |
+
all_image_files = alt_images
|
259 |
+
print(f"🔍 DEBUG: Using images from alternative path: {alt_path}")
|
260 |
+
break
|
261 |
+
|
262 |
if all_image_files:
|
263 |
image_files = all_image_files
|
264 |
+
print(f"🔍 DEBUG: Using image files from alternative search: {len(image_files)}")
|
265 |
else:
|
266 |
raise gr.Error("No images found in OSS for final video creation")
|
267 |
|