add debug info
Browse files- oss_utils.py +47 -0
- simulation.py +14 -3
oss_utils.py
CHANGED
@@ -25,6 +25,21 @@ 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
|
@@ -90,6 +105,38 @@ def get_user_tmp_dir(session_hash: str) -> str:
|
|
90 |
os.makedirs(user_dir, exist_ok=True)
|
91 |
return user_dir
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
def cleanup_user_tmp_dir(session_hash: str):
|
94 |
"""清理用户临时目录"""
|
95 |
user_dir = os.path.join(TMP_ROOT, str(session_hash))
|
|
|
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 |
+
|
29 |
+
# 测试OSS连接
|
30 |
+
try:
|
31 |
+
# 尝试列出bucket根目录的文件来测试连接
|
32 |
+
test_files = []
|
33 |
+
for i, obj in enumerate(oss2.ObjectIterator(bucket, max_keys=5)):
|
34 |
+
test_files.append(obj.key)
|
35 |
+
if i >= 4: # 只获取前5个
|
36 |
+
break
|
37 |
+
print(f"✅ OSS connection test successful, found {len(test_files)} test files")
|
38 |
+
if test_files:
|
39 |
+
print(f" Sample files: {test_files[:3]}")
|
40 |
+
except Exception as test_e:
|
41 |
+
print(f"⚠️ OSS connection test failed: {test_e}")
|
42 |
+
|
43 |
except Exception as e:
|
44 |
print(f"❌ OSS client initialization failed: {e}")
|
45 |
bucket = None
|
|
|
105 |
os.makedirs(user_dir, exist_ok=True)
|
106 |
return user_dir
|
107 |
|
108 |
+
def test_oss_access(task_id: str = None):
|
109 |
+
"""测试OSS访问并查找特定任务的文件"""
|
110 |
+
if bucket is None:
|
111 |
+
print("❌ Cannot test OSS access - bucket not initialized")
|
112 |
+
return
|
113 |
+
|
114 |
+
test_paths = [
|
115 |
+
"gradio_demo/",
|
116 |
+
"gradio_demo/tasks/",
|
117 |
+
]
|
118 |
+
|
119 |
+
if task_id:
|
120 |
+
test_paths.extend([
|
121 |
+
f"gradio_demo/tasks/{task_id}/",
|
122 |
+
f"gradio_demo/tasks/{task_id}/images/",
|
123 |
+
f"gradio_demo/tasks/{task_id}/image/",
|
124 |
+
])
|
125 |
+
|
126 |
+
for path in test_paths:
|
127 |
+
try:
|
128 |
+
print(f"🔍 Testing path: {path}")
|
129 |
+
files = []
|
130 |
+
for i, obj in enumerate(oss2.ObjectIterator(bucket, prefix=path, max_keys=10)):
|
131 |
+
files.append(obj.key)
|
132 |
+
if i >= 9:
|
133 |
+
break
|
134 |
+
print(f" Found {len(files)} files")
|
135 |
+
if files:
|
136 |
+
print(f" Sample: {files[:3]}")
|
137 |
+
except Exception as e:
|
138 |
+
print(f" ❌ Error: {e}")
|
139 |
+
|
140 |
def cleanup_user_tmp_dir(session_hash: str):
|
141 |
"""清理用户临时目录"""
|
142 |
user_dir = os.path.join(TMP_ROOT, str(session_hash))
|
simulation.py
CHANGED
@@ -8,7 +8,7 @@ import numpy as np
|
|
8 |
from typing import List
|
9 |
import gradio as gr
|
10 |
from backend_api import get_task_status
|
11 |
-
from oss_utils import list_oss_files, download_oss_file, get_user_tmp_dir
|
12 |
|
13 |
def stream_simulation_results(result_folder: str, task_id: str, request: gr.Request, fps: int = 6):
|
14 |
"""
|
@@ -205,6 +205,10 @@ def create_final_video_from_oss_images(result_folder: str, task_id: str, request
|
|
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)
|
@@ -220,6 +224,10 @@ def create_final_video_from_oss_images(result_folder: str, task_id: str, request
|
|
220 |
print(f"🔍 DEBUG: local_image_dir = {local_image_dir}")
|
221 |
|
222 |
try:
|
|
|
|
|
|
|
|
|
223 |
# 1. 获取OSS上的所有图片文件
|
224 |
print(f"🔍 DEBUG: Listing files in OSS folder: {image_folder}")
|
225 |
oss_files = list_oss_files(image_folder)
|
@@ -245,8 +253,11 @@ def create_final_video_from_oss_images(result_folder: str, task_id: str, request
|
|
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:
|
|
|
8 |
from typing import List
|
9 |
import gradio as gr
|
10 |
from backend_api import get_task_status
|
11 |
+
from oss_utils import list_oss_files, download_oss_file, get_user_tmp_dir, test_oss_access
|
12 |
|
13 |
def stream_simulation_results(result_folder: str, task_id: str, request: gr.Request, fps: int = 6):
|
14 |
"""
|
|
|
205 |
elif cleaned_result_folder.startswith('/oss-waic/'):
|
206 |
cleaned_result_folder = cleaned_result_folder[10:] # 移除 '/oss-waic/' 前缀
|
207 |
|
208 |
+
# 确保路径是正确的格式:gradio_demo/tasks/task_id
|
209 |
+
if not cleaned_result_folder.startswith('gradio_demo/'):
|
210 |
+
cleaned_result_folder = f"gradio_demo/tasks/{task_id}"
|
211 |
+
|
212 |
# 获取图片文件夹路径
|
213 |
image_folder = os.path.join(cleaned_result_folder, "images").replace('\\', '/')
|
214 |
user_dir = get_user_tmp_dir(request.session_hash)
|
|
|
224 |
print(f"🔍 DEBUG: local_image_dir = {local_image_dir}")
|
225 |
|
226 |
try:
|
227 |
+
# 首先测试OSS访问
|
228 |
+
print(f"🔍 DEBUG: Testing OSS access for task {task_id}")
|
229 |
+
test_oss_access(task_id)
|
230 |
+
|
231 |
# 1. 获取OSS上的所有图片文件
|
232 |
print(f"🔍 DEBUG: Listing files in OSS folder: {image_folder}")
|
233 |
oss_files = list_oss_files(image_folder)
|
|
|
253 |
alternative_paths = [
|
254 |
f"gradio_demo/tasks/{task_id}/images",
|
255 |
f"gradio_demo/tasks/{task_id}",
|
256 |
+
f"tasks/{task_id}/images",
|
257 |
+
f"tasks/{task_id}",
|
258 |
+
# 根据您确认的路径格式添加
|
259 |
+
f"gradio_demo/tasks/{task_id}/image", # 可能是单数形式
|
260 |
+
f"gradio_demo/tasks/{task_id}/imgs", # 可能是缩写
|
261 |
]
|
262 |
|
263 |
for alt_path in alternative_paths:
|