Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -377,8 +377,13 @@ class UnifiedProgressTqdm(tqdm):
|
|
| 377 |
# 🌟 1. 下载 LoRA 进度 (保持原样)
|
| 378 |
# ========================================================
|
| 379 |
if _current_download_task_id and _current_download_task_id in tasks_status:
|
| 380 |
-
|
| 381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
| 383 |
# ========================================================
|
| 384 |
# 🌟 2. ComfyUI 跑图进度
|
|
@@ -1133,24 +1138,19 @@ app.add_middleware(
|
|
| 1133 |
|
| 1134 |
from model_config import CORE_STATUS # 🌟 导入刚才写好的状态
|
| 1135 |
|
| 1136 |
-
|
| 1137 |
-
|
| 1138 |
frontend_url = MODEL_CONFIG.get("frontend_url", "#")
|
| 1139 |
-
|
| 1140 |
-
# 1. 读取 HTML
|
| 1141 |
html_path = os.path.join(os.path.dirname(__file__), "index.html")
|
| 1142 |
with open(html_path, "r", encoding="utf-8") as f:
|
| 1143 |
html_content = f.read()
|
| 1144 |
|
| 1145 |
-
# 2. 替换前端 URL
|
| 1146 |
html_content = html_content.replace("__FRONTEND_URL__", frontend_url)
|
| 1147 |
-
|
| 1148 |
-
# 3. 🌟 替换状态数据
|
| 1149 |
html_content = html_content.replace("__DEV_MODE__", "True" if CORE_STATUS["dev_mode"] else "False")
|
| 1150 |
html_content = html_content.replace("__TARGET_MODEL__", CORE_STATUS["target_model"])
|
| 1151 |
html_content = html_content.replace("__GRADIO_UI__", "Enabled" if CORE_STATUS["gradio_ui"] else "Disabled")
|
| 1152 |
|
| 1153 |
-
return html_content
|
| 1154 |
|
| 1155 |
|
| 1156 |
# 2. 挂载 API 路由(严格带上 /api 前缀)
|
|
@@ -1278,6 +1278,11 @@ if __name__ == "__main__":
|
|
| 1278 |
)
|
| 1279 |
else:
|
| 1280 |
print("🚀 Gradio UI is DISABLED. Running in pure API mode...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1281 |
def trigger_gpu_scan():
|
| 1282 |
demo.launch(
|
| 1283 |
server_name="127.0.0.1",
|
|
|
|
| 377 |
# 🌟 1. 下载 LoRA 进度 (保持原样)
|
| 378 |
# ========================================================
|
| 379 |
if _current_download_task_id and _current_download_task_id in tasks_status:
|
| 380 |
+
if self.total and self.total > 0:
|
| 381 |
+
percent = int((self.n / self.total) * 100)
|
| 382 |
+
tasks_status[_current_download_task_id]["message"] = f"📥 Downloading LoRA: {percent}%..."
|
| 383 |
+
else:
|
| 384 |
+
# 如果 total 拿不到,至少把当前下载了多少字节告诉前端
|
| 385 |
+
tasks_status[_current_download_task_id]["message"] = f"📥 Downloading LoRA: {self.n} units..."
|
| 386 |
+
return # 🌟 下载完毕直接 return,绝不往下走去碰跑图逻辑
|
| 387 |
|
| 388 |
# ========================================================
|
| 389 |
# 🌟 2. ComfyUI 跑图进度
|
|
|
|
| 1138 |
|
| 1139 |
from model_config import CORE_STATUS # 🌟 导入刚才写好的状态
|
| 1140 |
|
| 1141 |
+
async def serve_html():
|
| 1142 |
+
# 直接读取并返回 HTML
|
| 1143 |
frontend_url = MODEL_CONFIG.get("frontend_url", "#")
|
|
|
|
|
|
|
| 1144 |
html_path = os.path.join(os.path.dirname(__file__), "index.html")
|
| 1145 |
with open(html_path, "r", encoding="utf-8") as f:
|
| 1146 |
html_content = f.read()
|
| 1147 |
|
|
|
|
| 1148 |
html_content = html_content.replace("__FRONTEND_URL__", frontend_url)
|
|
|
|
|
|
|
| 1149 |
html_content = html_content.replace("__DEV_MODE__", "True" if CORE_STATUS["dev_mode"] else "False")
|
| 1150 |
html_content = html_content.replace("__TARGET_MODEL__", CORE_STATUS["target_model"])
|
| 1151 |
html_content = html_content.replace("__GRADIO_UI__", "Enabled" if CORE_STATUS["gradio_ui"] else "Disabled")
|
| 1152 |
|
| 1153 |
+
return HTMLResponse(content=html_content)
|
| 1154 |
|
| 1155 |
|
| 1156 |
# 2. 挂载 API 路由(严格带上 /api 前缀)
|
|
|
|
| 1278 |
)
|
| 1279 |
else:
|
| 1280 |
print("🚀 Gradio UI is DISABLED. Running in pure API mode...")
|
| 1281 |
+
|
| 1282 |
+
# 🌟 核心修复 2:关闭 Gradio 时,手动把 HTML 挂载到 `/` 路径
|
| 1283 |
+
# (注意:这里的 serve_html 函数就是我们在上一步里剥离出来的那个函数)
|
| 1284 |
+
app.add_api_route("/", serve_html, methods=["GET"], response_class=HTMLResponse)
|
| 1285 |
+
|
| 1286 |
def trigger_gpu_scan():
|
| 1287 |
demo.launch(
|
| 1288 |
server_name="127.0.0.1",
|