diff --git a/app.py b/app.py index 18b2b3a..2025bdf 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,7 @@ from werkzeug.security import check_password_hash from PIL import Image, UnidentifiedImageError from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler +from os.path import realpath, join app = Flask(__name__) @@ -16,8 +17,8 @@ with open('db/keys.json', 'r') as f: app.config['SECRET_KEY'] = config['key'] socketio = SocketIO(app) -app.config['UPLOAD_FOLDER'] = 'images' # Folder to store images -app.config['DUMP_FOLDER'] = 'dump_images' +app.config['UPLOAD_FOLDER'] = '/home/kenny/workspace/Image_Gen_Server/output/expo_postprocessed' # Folder to store images +app.config['DUMP_FOLDER'] = '/home/kenny/workspace/ComfyUI-halloween/output' # Folder to store dump images app.config['CACHE_FOLDER'] = 'cache' # Folder to store cached resized images app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'gif'} @@ -45,13 +46,12 @@ def resize_image(image_path, cache_path, size=(800, 450)): img.save(cache_path, format="JPEG") def create_cache(): - images = os.listdir(app.config['UPLOAD_FOLDER']) cached_images = [] if not os.path.exists(app.config['CACHE_FOLDER']): os.makedirs(app.config['CACHE_FOLDER']) - for image in images: + for image in os.listdir(app.config['UPLOAD_FOLDER']): image_path = os.path.join(app.config['UPLOAD_FOLDER'], image) cache_path = os.path.join(app.config['CACHE_FOLDER'], image) @@ -60,6 +60,16 @@ def create_cache(): if is_image_valid(image_path): cached_images.append(image) + + for image in os.listdir(app.config['DUMP_FOLDER']): + image_path = os.path.join(app.config['DUMP_FOLDER'], image) + cache_path = os.path.join(app.config['CACHE_FOLDER'], image) + + if not os.path.exists(cache_path) and is_image_valid(image_path): + resize_image(image_path, cache_path) + + if is_image_valid(image_path): + cached_images.append(image) return cached_images @@ -157,6 +167,7 @@ def dump(): if not session.get('logged_in'): return redirect(url_for('login')) + cached_images = create_cache() dump_folder = app.config['DUMP_FOLDER'] # Folder to store dump images images = sorted( os.listdir(dump_folder), @@ -164,6 +175,7 @@ def dump(): reverse=True ) valid_images = [img for img in images if is_image_valid(os.path.join(dump_folder, img))] + print(valid_images) return render_template('dump.html', images=valid_images) def emit_gallery_update(): @@ -199,4 +211,4 @@ if __name__ == '__main__': socketio.run(app, debug=True, ssl_context=context) except KeyboardInterrupt: observer.stop() - observer.join() \ No newline at end of file + observer.join() diff --git a/templates/dump.html b/templates/dump.html index 5b2286b..ba30462 100644 --- a/templates/dump.html +++ b/templates/dump.html @@ -11,12 +11,22 @@ πππ