Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,6 +37,7 @@ _enhancer_ready = False
|
|
| 37 |
_enhancer_lock = threading.Lock()
|
| 38 |
_enhancer_server_proc = None
|
| 39 |
ENHANCER_PORT = 18642
|
|
|
|
| 40 |
|
| 41 |
def _server_binary_path() -> pathlib.Path:
|
| 42 |
if CACHED_BINARY_PATH.exists():
|
|
@@ -175,23 +176,39 @@ def _start_enhancer_server() -> None:
|
|
| 175 |
return
|
| 176 |
except Exception:
|
| 177 |
pass
|
|
|
|
| 178 |
server_bin = _server_binary_path()
|
| 179 |
server_env = dict(os.environ)
|
| 180 |
if CACHED_LIBS_DIR.exists():
|
| 181 |
server_env["LD_LIBRARY_PATH"] = f"{CACHED_LIBS_DIR}:{server_env.get('LD_LIBRARY_PATH','')}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
_enhancer_server_proc = subprocess.Popen([
|
| 183 |
str(server_bin), "-m", str(SULPHUR_MODEL_PATH), "--mmproj", str(SULPHUR_MMPROJ_PATH),
|
| 184 |
-
"-ngl", "99", "-c", "8192", "--flash-attn", "
|
| 185 |
-
], stdout=
|
|
|
|
| 186 |
for _ in range(60):
|
| 187 |
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
try:
|
| 189 |
r = http_requests.get(f"http://127.0.0.1:{ENHANCER_PORT}/health", timeout=2)
|
| 190 |
if r.json().get("status") == "ok":
|
|
|
|
| 191 |
return
|
| 192 |
except Exception:
|
| 193 |
pass
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
def _enhance_prompt_impl(image_path: str, concept: str) -> str:
|
| 197 |
with _enhancer_lock:
|
|
@@ -232,10 +249,11 @@ def generate_three_prompts(image_path: str, base_prompt: str) -> tuple[str, str,
|
|
| 232 |
p2 = _enhance_prompt_impl(image_path, f"{base_prompt.strip()} - Part 2: Continuing the movement, mid-sequence evolution, logical progression.")
|
| 233 |
p3 = _enhance_prompt_impl(image_path, f"{base_prompt.strip()} - Part 3: Climax of the motion, final frames, completing the 15-second visual arc.")
|
| 234 |
return p1, p2, p3
|
| 235 |
-
except Exception:
|
| 236 |
tb = traceback.format_exc()
|
| 237 |
print(tb, flush=True)
|
| 238 |
-
|
|
|
|
| 239 |
|
| 240 |
if os.environ.get("SKIP_STARTUP_SETUP") != "1":
|
| 241 |
_ensure_enhancer()
|
|
|
|
| 37 |
_enhancer_lock = threading.Lock()
|
| 38 |
_enhancer_server_proc = None
|
| 39 |
ENHANCER_PORT = 18642
|
| 40 |
+
LOG_PATH = ROOT / "llama_server.log"
|
| 41 |
|
| 42 |
def _server_binary_path() -> pathlib.Path:
|
| 43 |
if CACHED_BINARY_PATH.exists():
|
|
|
|
| 176 |
return
|
| 177 |
except Exception:
|
| 178 |
pass
|
| 179 |
+
|
| 180 |
server_bin = _server_binary_path()
|
| 181 |
server_env = dict(os.environ)
|
| 182 |
if CACHED_LIBS_DIR.exists():
|
| 183 |
server_env["LD_LIBRARY_PATH"] = f"{CACHED_LIBS_DIR}:{server_env.get('LD_LIBRARY_PATH','')}"
|
| 184 |
+
|
| 185 |
+
# هدایت خروجی خطاها به فایل متنی برای عیبیابی راحتتر
|
| 186 |
+
log_file = open(LOG_PATH, "w", encoding="utf-8")
|
| 187 |
+
|
| 188 |
_enhancer_server_proc = subprocess.Popen([
|
| 189 |
str(server_bin), "-m", str(SULPHUR_MODEL_PATH), "--mmproj", str(SULPHUR_MMPROJ_PATH),
|
| 190 |
+
"-ngl", "99", "-c", "8192", "--flash-attn", "off", "--host", "127.0.0.1", "--port", str(ENHANCER_PORT)
|
| 191 |
+
], stdout=log_file, stderr=log_file, env=server_env)
|
| 192 |
+
|
| 193 |
for _ in range(60):
|
| 194 |
time.sleep(1)
|
| 195 |
+
# بررسی اینکه آیا پروسه درجا کرش کرده است یا نه
|
| 196 |
+
if _enhancer_server_proc.poll() is not None:
|
| 197 |
+
log_file.close()
|
| 198 |
+
err_logs = LOG_PATH.read_text(encoding="utf-8") if LOG_PATH.exists() else "No logs available"
|
| 199 |
+
raise RuntimeError(f"llama-server crashed instantly with code {_enhancer_server_proc.returncode}.\nServer Logs:\n{err_logs[-1500:]}")
|
| 200 |
+
|
| 201 |
try:
|
| 202 |
r = http_requests.get(f"http://127.0.0.1:{ENHANCER_PORT}/health", timeout=2)
|
| 203 |
if r.json().get("status") == "ok":
|
| 204 |
+
log_file.close()
|
| 205 |
return
|
| 206 |
except Exception:
|
| 207 |
pass
|
| 208 |
+
|
| 209 |
+
log_file.close()
|
| 210 |
+
err_logs = LOG_PATH.read_text(encoding="utf-8") if LOG_PATH.exists() else "No logs available"
|
| 211 |
+
raise RuntimeError(f"llama-server timed out after 60s.\nServer Logs:\n{err_logs[-1500:]}")
|
| 212 |
|
| 213 |
def _enhance_prompt_impl(image_path: str, concept: str) -> str:
|
| 214 |
with _enhancer_lock:
|
|
|
|
| 249 |
p2 = _enhance_prompt_impl(image_path, f"{base_prompt.strip()} - Part 2: Continuing the movement, mid-sequence evolution, logical progression.")
|
| 250 |
p3 = _enhance_prompt_impl(image_path, f"{base_prompt.strip()} - Part 3: Climax of the motion, final frames, completing the 15-second visual arc.")
|
| 251 |
return p1, p2, p3
|
| 252 |
+
except Exception as exc:
|
| 253 |
tb = traceback.format_exc()
|
| 254 |
print(tb, flush=True)
|
| 255 |
+
# نمایش مستقیم لاگها و علت خطا درون وبسایت
|
| 256 |
+
raise gr.Error(f"Execution Error: {str(exc)}")
|
| 257 |
|
| 258 |
if os.environ.get("SKIP_STARTUP_SETUP") != "1":
|
| 259 |
_ensure_enhancer()
|