LPX55 commited on
Commit
9202118
·
1 Parent(s): c6f8b7e
Files changed (1) hide show
  1. debug.py +12 -4
debug.py CHANGED
@@ -5,6 +5,7 @@ import uuid
5
  import time
6
  from huggingface_hub import CommitScheduler, HfApi
7
  from PIL import Image
 
8
 
9
  APP_VERSION = "0_3"
10
  HF_DATASET_REPO = "LPX55/upscaler_logs" # Change to your dataset repo
@@ -14,7 +15,6 @@ LOG_DIR = "logs_" + APP_VERSION
14
  IMAGE_DIR = os.path.join(LOG_DIR, "upscaler")
15
 
16
  LOG_FILE = os.path.join(LOG_DIR, f"{int(time.time())}-logs.csv")
17
- os.makedirs(IMAGE_DIR, exist_ok=True)
18
 
19
 
20
  scheduler = CommitScheduler(
@@ -24,10 +24,18 @@ scheduler = CommitScheduler(
24
  every=5,
25
  private=True,
26
  token=HF_TOKEN,
27
- allow_patterns=["*.csv", "images/*.png", "images/*.webp", "images/*.jpg", "images/*.jpeg"],
28
  path_in_repo="v" + APP_VERSION
29
 
30
  )
 
 
 
 
 
 
 
 
 
31
 
32
  def log_params(
33
  prompt, scale, steps, controlnet_conditioning_scale, guidance_scale, seed, guidance_end,
@@ -37,8 +45,8 @@ def log_params(
37
  after_id = str(uuid.uuid4()) + "_after.png"
38
  before_path = os.path.join(IMAGE_DIR, before_id)
39
  after_path = os.path.join(IMAGE_DIR, after_id)
40
- before_image.save(before_path)
41
- after_image.save(after_path)
42
 
43
  is_new = not os.path.exists(LOG_FILE)
44
  with open(LOG_FILE, "a", newline='') as f:
 
5
  import time
6
  from huggingface_hub import CommitScheduler, HfApi
7
  from PIL import Image
8
+ import numpy as np
9
 
10
  APP_VERSION = "0_3"
11
  HF_DATASET_REPO = "LPX55/upscaler_logs" # Change to your dataset repo
 
15
  IMAGE_DIR = os.path.join(LOG_DIR, "upscaler")
16
 
17
  LOG_FILE = os.path.join(LOG_DIR, f"{int(time.time())}-logs.csv")
 
18
 
19
 
20
  scheduler = CommitScheduler(
 
24
  every=5,
25
  private=True,
26
  token=HF_TOKEN,
 
27
  path_in_repo="v" + APP_VERSION
28
 
29
  )
30
+ def save_image(image_id: str, image_array: np.ndarray) -> None:
31
+ os.makedirs(IMAGE_DIR, exist_ok=True)
32
+ image_path = IMAGE_DIR / f"{image_id}.png"
33
+ with scheduler.lock:
34
+ try:
35
+ Image.fromarray(image_array).save(image_path)
36
+ print(f"Saved image: {image_path}")
37
+ except Exception as e:
38
+ print(f"Error saving image: {str(e)}")
39
 
40
  def log_params(
41
  prompt, scale, steps, controlnet_conditioning_scale, guidance_scale, seed, guidance_end,
 
45
  after_id = str(uuid.uuid4()) + "_after.png"
46
  before_path = os.path.join(IMAGE_DIR, before_id)
47
  after_path = os.path.join(IMAGE_DIR, after_id)
48
+ save_image(before_id, before_image)
49
+ save_image(after_id, after_image)
50
 
51
  is_new = not os.path.exists(LOG_FILE)
52
  with open(LOG_FILE, "a", newline='') as f: