ai-frame-image-server/ai_frame_image_server.py

51 lines
1.4 KiB
Python
Raw Normal View History

2025-06-24 13:01:39 +01:00
from flask import Flask
from libs.generic import load_config
2025-03-28 18:37:58 +00:00
import os
2025-03-29 12:24:46 +00:00
2025-06-24 13:01:39 +01:00
from routes import (
auth_routes,
gallery_routes,
image_routes,
index_routes,
job_routes,
create_routes,
settings_routes
)
2025-03-29 12:24:46 +00:00
user_config = load_config()
2025-03-28 18:37:58 +00:00
app = Flask(__name__)
2025-06-24 13:01:39 +01:00
app.secret_key = os.environ.get("SECRET_KEY")
# Inject config into routes that need it
create_routes.init_app(user_config)
auth_routes.init_app(user_config)
# Register blueprints
app.register_blueprint(index_routes.bp)
app.register_blueprint(auth_routes.bp)
app.register_blueprint(gallery_routes.bp)
app.register_blueprint(image_routes.bp)
app.register_blueprint(job_routes.bp)
app.register_blueprint(create_routes.bp)
app.register_blueprint(settings_routes.bp)
# Optional: scheduler setup
from apscheduler.schedulers.background import BackgroundScheduler
import time
from libs.comfyui import create_image
2025-06-24 13:01:39 +01:00
def scheduled_task():
print(f"Executing scheduled task at {time.strftime('%Y-%m-%d %H:%M:%S')}")
create_image(None)
if user_config["frame"]["auto_regen"] == "True":
2025-04-07 08:34:56 +01:00
if os.environ.get("WERKZEUG_RUN_MAIN") == "true":
scheduler = BackgroundScheduler()
2025-06-24 13:01:39 +01:00
h, m = user_config["frame"]["regen_time"].split(":")
scheduler.add_job(scheduled_task, "cron", hour=h, minute=m, id="scheduled_task", max_instances=1, replace_existing=True)
2025-04-07 08:34:56 +01:00
scheduler.start()
2025-06-24 13:01:39 +01:00
os.makedirs("./output", exist_ok=True)
app.run(host="0.0.0.0", port=user_config["frame"]["port"], debug=True)