mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-04-28 19:23:41 +01:00
support auto image regeneration at specific time
This commit is contained in:
parent
d97ef3f171
commit
290c1badb4
@ -1,22 +1,38 @@
|
|||||||
from flask import Flask, render_template, send_from_directory, redirect, url_for, request, jsonify
|
from flask import (
|
||||||
|
Flask,
|
||||||
|
render_template,
|
||||||
|
send_from_directory,
|
||||||
|
redirect,
|
||||||
|
url_for,
|
||||||
|
request,
|
||||||
|
jsonify,
|
||||||
|
)
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from lib import create_image, load_config
|
from lib import create_image, load_config
|
||||||
|
|
||||||
user_config = load_config()
|
user_config = load_config()
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
image_folder = "./output"
|
image_folder = "./output"
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def index():
|
|
||||||
return render_template("index.html", image="./image.png", reload_interval=user_config["frame"]["reload_interval"])
|
|
||||||
|
|
||||||
@app.route('/images/<filename>')
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
return render_template(
|
||||||
|
"index.html",
|
||||||
|
image="./image.png",
|
||||||
|
reload_interval=user_config["frame"]["reload_interval"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/images/<filename>")
|
||||||
def images(filename):
|
def images(filename):
|
||||||
return send_from_directory(image_folder, filename)
|
return send_from_directory(image_folder, filename)
|
||||||
|
|
||||||
@app.route('/create', methods=["GET", "POST"])
|
|
||||||
|
@app.route("/create", methods=["GET", "POST"])
|
||||||
def create():
|
def create():
|
||||||
"""Endpoint to create a new image. Supports optional prompt via POST."""
|
"""Endpoint to create a new image. Supports optional prompt via POST."""
|
||||||
prompt = request.form.get("prompt") if request.method == "POST" else None
|
prompt = request.form.get("prompt") if request.method == "POST" else None
|
||||||
@ -27,7 +43,21 @@ def create():
|
|||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def scheduled_task():
|
||||||
os.makedirs(image_folder, exist_ok=True) # Ensure the folder exists
|
print(f"Executing scheduled task at {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
app.run(host="0.0.0.0", port=user_config["frame"]["port"], debug=True)
|
create_image(None)
|
||||||
|
|
||||||
|
|
||||||
|
if user_config["frame"]["auto_regen"] == "True":
|
||||||
|
scheduler = BackgroundScheduler()
|
||||||
|
|
||||||
|
regen_time = user_config["frame"]["regen_time"].split(":")
|
||||||
|
scheduler.add_job(scheduled_task, "cron", hour=regen_time[0], minute=regen_time[1])
|
||||||
|
scheduler.start()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
os.makedirs(image_folder, exist_ok=True) # Ensure the folder exists
|
||||||
|
try:
|
||||||
|
app.run(host="0.0.0.0", port=user_config["frame"]["port"], debug=True)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
scheduler.shutdown() # Ensure graceful shutdown of scheduler
|
||||||
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@ -1,5 +1,7 @@
|
|||||||
[frame]
|
[frame]
|
||||||
reload_interval = 30000
|
reload_interval = 30000
|
||||||
|
auto_regen = True
|
||||||
|
regen_time = 03:00
|
||||||
port = 5000
|
port = 5000
|
||||||
|
|
||||||
[comfyui]
|
[comfyui]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user