Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,10 @@ import gradio as gr
|
|
5 |
from pathlib import Path
|
6 |
import subprocess, json, tempfile, sys
|
7 |
|
8 |
-
#
|
9 |
COMFY_DIR = Path("ComfyUI")
|
10 |
WORKFLOW_JSON = Path("workflow_api.json")
|
11 |
-
|
12 |
-
# ✅ Correction ici : logs en dossier local
|
13 |
-
LOGS_DIR = Path("logs")
|
14 |
LOGS_DIR.mkdir(parents=True, exist_ok=True)
|
15 |
|
16 |
def patch_workflow(wf, pic_path, face_path, prompt):
|
@@ -25,7 +23,7 @@ def patch_workflow(wf, pic_path, face_path, prompt):
|
|
25 |
|
26 |
def run(picture, face, positive):
|
27 |
tmpdir = Path(tempfile.mkdtemp())
|
28 |
-
pic_path
|
29 |
face_path = tmpdir / "face.png"
|
30 |
picture.save(pic_path)
|
31 |
face.save(face_path)
|
@@ -38,7 +36,6 @@ def run(picture, face, positive):
|
|
38 |
with open(tmp_wf, "w") as f:
|
39 |
json.dump(wf, f)
|
40 |
|
41 |
-
# Lancement de ComfyUI
|
42 |
result = subprocess.run([
|
43 |
sys.executable, "main.py",
|
44 |
"--disable-auto-launch",
|
@@ -47,7 +44,6 @@ def run(picture, face, positive):
|
|
47 |
"--workflow", str(tmp_wf)
|
48 |
], cwd=COMFY_DIR, capture_output=True, text=True)
|
49 |
|
50 |
-
# ✅ Sauvegarde des logs dans ./logs
|
51 |
log_file = LOGS_DIR / "comfy.txt"
|
52 |
with open(log_file, "w") as f:
|
53 |
f.write("=== STDOUT ===\n")
|
@@ -58,7 +54,6 @@ def run(picture, face, positive):
|
|
58 |
if result.returncode != 0:
|
59 |
raise RuntimeError("ComfyUI failed to run — voir comfy.txt dans Files.")
|
60 |
|
61 |
-
# Vérifie la sortie image
|
62 |
out = list(tmpdir.glob("*.png"))
|
63 |
if not out:
|
64 |
raise RuntimeError("No output image generated.")
|
|
|
5 |
from pathlib import Path
|
6 |
import subprocess, json, tempfile, sys
|
7 |
|
8 |
+
# Répertoires
|
9 |
COMFY_DIR = Path("ComfyUI")
|
10 |
WORKFLOW_JSON = Path("workflow_api.json")
|
11 |
+
LOGS_DIR = Path(tempfile.gettempdir()) / "comfy_logs"
|
|
|
|
|
12 |
LOGS_DIR.mkdir(parents=True, exist_ok=True)
|
13 |
|
14 |
def patch_workflow(wf, pic_path, face_path, prompt):
|
|
|
23 |
|
24 |
def run(picture, face, positive):
|
25 |
tmpdir = Path(tempfile.mkdtemp())
|
26 |
+
pic_path = tmpdir / "pic.png"
|
27 |
face_path = tmpdir / "face.png"
|
28 |
picture.save(pic_path)
|
29 |
face.save(face_path)
|
|
|
36 |
with open(tmp_wf, "w") as f:
|
37 |
json.dump(wf, f)
|
38 |
|
|
|
39 |
result = subprocess.run([
|
40 |
sys.executable, "main.py",
|
41 |
"--disable-auto-launch",
|
|
|
44 |
"--workflow", str(tmp_wf)
|
45 |
], cwd=COMFY_DIR, capture_output=True, text=True)
|
46 |
|
|
|
47 |
log_file = LOGS_DIR / "comfy.txt"
|
48 |
with open(log_file, "w") as f:
|
49 |
f.write("=== STDOUT ===\n")
|
|
|
54 |
if result.returncode != 0:
|
55 |
raise RuntimeError("ComfyUI failed to run — voir comfy.txt dans Files.")
|
56 |
|
|
|
57 |
out = list(tmpdir.glob("*.png"))
|
58 |
if not out:
|
59 |
raise RuntimeError("No output image generated.")
|