add debug info
Browse files- app.py +2 -2
- oss_utils.py +14 -0
- simulation.py +3 -11
app.py
CHANGED
@@ -6,7 +6,7 @@ from backend_api import submit_to_backend, get_task_status, get_task_result
|
|
6 |
from logging_utils import log_access, log_submission, is_request_allowed
|
7 |
from simulation import stream_simulation_results, convert_to_h264, create_final_video_from_oss_images
|
8 |
from ui_components import update_history_display, update_scene_display, update_log_display, get_scene_instruction
|
9 |
-
from oss_utils import download_oss_file, get_user_tmp_dir, cleanup_user_tmp_dir, oss_file_exists
|
10 |
import os
|
11 |
from datetime import datetime
|
12 |
|
@@ -37,7 +37,7 @@ def run_simulation(scene, model, mode, prompt, history, request: gr.Request):
|
|
37 |
time.sleep(5)
|
38 |
status = get_task_status(task_id)
|
39 |
# OSS上的结果文件夹路径,不再检查本地路径是否存在
|
40 |
-
result_folder = status.get("result", f"gradio_demo/tasks/{task_id}")
|
41 |
|
42 |
except Exception as e:
|
43 |
log_submission(scene, prompt, model, user_ip, str(e))
|
|
|
6 |
from logging_utils import log_access, log_submission, is_request_allowed
|
7 |
from simulation import stream_simulation_results, convert_to_h264, create_final_video_from_oss_images
|
8 |
from ui_components import update_history_display, update_scene_display, update_log_display, get_scene_instruction
|
9 |
+
from oss_utils import download_oss_file, get_user_tmp_dir, cleanup_user_tmp_dir, oss_file_exists, clean_oss_result_path
|
10 |
import os
|
11 |
from datetime import datetime
|
12 |
|
|
|
37 |
time.sleep(5)
|
38 |
status = get_task_status(task_id)
|
39 |
# OSS上的结果文件夹路径,不再检查本地路径是否存在
|
40 |
+
result_folder = clean_oss_result_path(status.get("result", f"gradio_demo/tasks/{task_id}"))
|
41 |
|
42 |
except Exception as e:
|
43 |
log_submission(scene, prompt, model, user_ip, str(e))
|
oss_utils.py
CHANGED
@@ -105,6 +105,20 @@ def get_user_tmp_dir(session_hash: str) -> str:
|
|
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:
|
|
|
105 |
os.makedirs(user_dir, exist_ok=True)
|
106 |
return user_dir
|
107 |
|
108 |
+
def clean_oss_result_path(result_folder: str, task_id: str) -> str:
|
109 |
+
"""统一的OSS结果路径清理函数"""
|
110 |
+
cleaned_result_folder = result_folder.strip('/')
|
111 |
+
if cleaned_result_folder.startswith('oss-waic/'):
|
112 |
+
cleaned_result_folder = cleaned_result_folder[9:] # 移除 'oss-waic/' 前缀
|
113 |
+
elif cleaned_result_folder.startswith('/oss-waic/'):
|
114 |
+
cleaned_result_folder = cleaned_result_folder[10:] # 移除 '/oss-waic/' 前缀
|
115 |
+
|
116 |
+
# 确保路径格式正确
|
117 |
+
if not cleaned_result_folder.startswith('gradio_demo/'):
|
118 |
+
cleaned_result_folder = f"gradio_demo/tasks/{task_id}"
|
119 |
+
|
120 |
+
return cleaned_result_folder
|
121 |
+
|
122 |
def test_oss_access(task_id: str = None):
|
123 |
"""测试OSS访问并查找特定任务的文件"""
|
124 |
if bucket is None:
|
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, test_oss_access
|
12 |
|
13 |
def stream_simulation_results(result_folder: str, task_id: str, request: gr.Request, fps: int = 6):
|
14 |
"""
|
@@ -198,16 +198,8 @@ def create_final_video_from_oss_images(result_folder: str, task_id: str, request
|
|
198 |
返回:
|
199 |
最终视频文件路径
|
200 |
"""
|
201 |
-
#
|
202 |
-
cleaned_result_folder = result_folder
|
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 |
-
# 确保路径是正确的格式: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('\\', '/')
|
|
|
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, clean_oss_result_path
|
12 |
|
13 |
def stream_simulation_results(result_folder: str, task_id: str, request: gr.Request, fps: int = 6):
|
14 |
"""
|
|
|
198 |
返回:
|
199 |
最终视频文件路径
|
200 |
"""
|
201 |
+
# 使用统一的路径清理函数
|
202 |
+
cleaned_result_folder = clean_oss_result_path(result_folder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
# 获取图片文件夹路径
|
205 |
image_folder = os.path.join(cleaned_result_folder, "images").replace('\\', '/')
|