Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,48 +19,6 @@ GALLERY_JSON = "/home/user/app/gallery.json"
|
|
| 19 |
# 갤러리 디렉토리 생성
|
| 20 |
os.makedirs(GALLERY_DIR, exist_ok=True)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
def save_to_gallery(image_path, prompt):
|
| 24 |
-
print(f"File permissions: {oct(os.stat(new_image_path).st_mode)[-3:]}") # 로그 추가
|
| 25 |
-
|
| 26 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 27 |
-
new_image_path = os.path.join(GALLERY_DIR, f"{timestamp}.png")
|
| 28 |
-
|
| 29 |
-
print(f"Saving image to: {new_image_path}") # 로그 추가
|
| 30 |
-
shutil.copy2(image_path, new_image_path)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# 갤러리 정보 저장
|
| 34 |
-
gallery_info = {
|
| 35 |
-
"image": new_image_path,
|
| 36 |
-
"prompt": prompt,
|
| 37 |
-
"timestamp": timestamp
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
if os.path.exists(GALLERY_JSON):
|
| 41 |
-
with open(GALLERY_JSON, "r") as f:
|
| 42 |
-
gallery = json.load(f)
|
| 43 |
-
else:
|
| 44 |
-
gallery = []
|
| 45 |
-
|
| 46 |
-
gallery.append(gallery_info)
|
| 47 |
-
|
| 48 |
-
with open(GALLERY_JSON, "w") as f:
|
| 49 |
-
json.dump(gallery, f, indent=2)
|
| 50 |
-
|
| 51 |
-
return new_image_path
|
| 52 |
-
|
| 53 |
-
def load_gallery():
|
| 54 |
-
if os.path.exists(GALLERY_JSON):
|
| 55 |
-
print(f"Gallery JSON permissions: {oct(os.stat(GALLERY_JSON).st_mode)[-3:]}") # 로그 추가
|
| 56 |
-
|
| 57 |
-
print(f"Loading gallery from: {GALLERY_JSON}") # 로그 추가
|
| 58 |
-
if os.path.exists(GALLERY_JSON):
|
| 59 |
-
with open(GALLERY_JSON, "r") as f:
|
| 60 |
-
gallery = json.load(f)
|
| 61 |
-
return [(item["image"], item["prompt"]) for item in reversed(gallery)]
|
| 62 |
-
return []
|
| 63 |
-
|
| 64 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
| 65 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
| 66 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
|
@@ -187,14 +145,66 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
| 187 |
outputs=gallery
|
| 188 |
)
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
def check_gallery_status():
|
| 191 |
print(f"Gallery directory exists: {os.path.exists(GALLERY_DIR)}")
|
| 192 |
print(f"Gallery JSON exists: {os.path.exists(GALLERY_JSON)}")
|
| 193 |
if os.path.exists(GALLERY_JSON):
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
check_gallery_status()
|
| 200 |
demo.launch()
|
|
|
|
| 19 |
# 갤러리 디렉토리 생성
|
| 20 |
os.makedirs(GALLERY_DIR, exist_ok=True)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
| 23 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
| 24 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
|
|
|
| 145 |
outputs=gallery
|
| 146 |
)
|
| 147 |
|
| 148 |
+
def load_gallery():
|
| 149 |
+
print(f"Loading gallery from: {GALLERY_JSON}") # 로그 추가
|
| 150 |
+
if os.path.exists(GALLERY_JSON):
|
| 151 |
+
print(f"Gallery JSON permissions: {oct(os.stat(GALLERY_JSON).st_mode)[-3:]}") # 로그 추가
|
| 152 |
+
try:
|
| 153 |
+
with open(GALLERY_JSON, "r") as f:
|
| 154 |
+
gallery = json.load(f)
|
| 155 |
+
return [(item["image"], item["prompt"]) for item in reversed(gallery)]
|
| 156 |
+
except Exception as e:
|
| 157 |
+
print(f"Error loading gallery: {str(e)}")
|
| 158 |
+
return []
|
| 159 |
+
|
| 160 |
def check_gallery_status():
|
| 161 |
print(f"Gallery directory exists: {os.path.exists(GALLERY_DIR)}")
|
| 162 |
print(f"Gallery JSON exists: {os.path.exists(GALLERY_JSON)}")
|
| 163 |
if os.path.exists(GALLERY_JSON):
|
| 164 |
+
try:
|
| 165 |
+
with open(GALLERY_JSON, "r") as f:
|
| 166 |
+
gallery = json.load(f)
|
| 167 |
+
print(f"Number of items in gallery: {len(gallery)}")
|
| 168 |
+
except Exception as e:
|
| 169 |
+
print(f"Error reading gallery JSON: {str(e)}")
|
| 170 |
+
|
| 171 |
+
def save_to_gallery(image_path, prompt):
|
| 172 |
+
try:
|
| 173 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 174 |
+
new_image_path = os.path.join(GALLERY_DIR, f"{timestamp}.png")
|
| 175 |
+
|
| 176 |
+
print(f"Saving image to: {new_image_path}") # 로그 추가
|
| 177 |
+
shutil.copy2(image_path, new_image_path)
|
| 178 |
+
|
| 179 |
+
print(f"File permissions: {oct(os.stat(new_image_path).st_mode)[-3:]}") # 로그 추가
|
| 180 |
|
| 181 |
+
gallery_info = {
|
| 182 |
+
"image": new_image_path,
|
| 183 |
+
"prompt": prompt,
|
| 184 |
+
"timestamp": timestamp
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
if os.path.exists(GALLERY_JSON):
|
| 188 |
+
with open(GALLERY_JSON, "r") as f:
|
| 189 |
+
gallery = json.load(f)
|
| 190 |
+
else:
|
| 191 |
+
gallery = []
|
| 192 |
+
|
| 193 |
+
gallery.append(gallery_info)
|
| 194 |
+
|
| 195 |
+
with open(GALLERY_JSON, "w") as f:
|
| 196 |
+
json.dump(gallery, f, indent=2)
|
| 197 |
+
|
| 198 |
+
return new_image_path
|
| 199 |
+
except Exception as e:
|
| 200 |
+
print(f"Error saving to gallery: {str(e)}")
|
| 201 |
+
raise
|
| 202 |
+
|
| 203 |
+
# 메인 부분에 다음 코드 추가
|
| 204 |
if __name__ == "__main__":
|
| 205 |
+
print("Environment variables:")
|
| 206 |
+
for key, value in os.environ.items():
|
| 207 |
+
print(f"{key}: {value}")
|
| 208 |
+
|
| 209 |
check_gallery_status()
|
| 210 |
demo.launch()
|