mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-04-28 19:23:41 +01:00
update with docker server
This commit is contained in:
parent
6ada0bfb18
commit
fc0b1f3166
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,5 +5,4 @@ script.log
|
|||||||
build/
|
build/
|
||||||
dist/
|
dist/
|
||||||
user_config.cfg
|
user_config.cfg
|
||||||
Dockerfile
|
|
||||||
output/**.*
|
output/**.*
|
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Use an official Python image as a base
|
||||||
|
FROM python:3.11
|
||||||
|
|
||||||
|
# Set the working directory in the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy project files into the container
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Expose any necessary ports (optional, if running a web app)
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
# Define the command to run the application
|
||||||
|
CMD ["python", "ai_frame_image_server.py"]
|
@ -6,19 +6,10 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
image_folder = "./output"
|
image_folder = "./output"
|
||||||
|
|
||||||
def get_latest_image():
|
|
||||||
"""Get the latest image file from the directory."""
|
|
||||||
files = [f for f in os.listdir(image_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
|
|
||||||
if not files:
|
|
||||||
return None
|
|
||||||
latest_file = max(files, key=lambda f: os.path.getmtime(os.path.join(image_folder, f)))
|
|
||||||
return latest_file
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
latest_image = get_latest_image()
|
# latest_image = get_latest_image()
|
||||||
return render_template("index.html", image=latest_image)
|
return render_template("index.html", image="./image.png")
|
||||||
|
|
||||||
@app.route('/images/<filename>')
|
@app.route('/images/<filename>')
|
||||||
def images(filename):
|
def images(filename):
|
||||||
@ -32,4 +23,5 @@ def create():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
os.makedirs(image_folder, exist_ok=True) # Ensure the folder exists
|
os.makedirs(image_folder, exist_ok=True) # Ensure the folder exists
|
||||||
app.run(debug=True)
|
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||||
|
|
||||||
|
24
lib.py
24
lib.py
@ -4,8 +4,7 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
import litellm
|
import litellm
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper
|
from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper
|
||||||
|
|
||||||
@ -19,6 +18,20 @@ except KeyError as e:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def rename_image():
|
||||||
|
"""Rename 'image.png' to a timestamped filename if it exists in the output folder."""
|
||||||
|
old_path = os.path.join(user_config["comfyui"]["output_dir"], "image.png")
|
||||||
|
|
||||||
|
if os.path.exists(old_path):
|
||||||
|
new_filename = f"{str(time.time())}.png"
|
||||||
|
new_path = os.path.join(user_config["comfyui"]["output_dir"], new_filename)
|
||||||
|
os.rename(old_path, new_path)
|
||||||
|
print(f"Renamed 'image.png' to '{new_filename}'")
|
||||||
|
return new_filename
|
||||||
|
else:
|
||||||
|
print("No image.png found.")
|
||||||
|
return None
|
||||||
|
|
||||||
def send_prompt_to_openwebui(prompt):
|
def send_prompt_to_openwebui(prompt):
|
||||||
response = litellm.completion(
|
response = litellm.completion(
|
||||||
api_base=user_config["openwebui"]["base_url"],
|
api_base=user_config["openwebui"]["base_url"],
|
||||||
@ -55,6 +68,7 @@ def generate_image(file_name, comfy_prompt):
|
|||||||
# Queue your workflow for completion
|
# Queue your workflow for completion
|
||||||
logging.debug(f"Generating image: {file_name}")
|
logging.debug(f"Generating image: {file_name}")
|
||||||
results = api.queue_and_wait_images(wf, "Save Image")
|
results = api.queue_and_wait_images(wf, "Save Image")
|
||||||
|
rename_image()
|
||||||
for filename, image_data in results.items():
|
for filename, image_data in results.items():
|
||||||
with open(
|
with open(
|
||||||
user_config["comfyui"]["output_dir"] + file_name + ".png", "wb+"
|
user_config["comfyui"]["output_dir"] + file_name + ".png", "wb+"
|
||||||
@ -69,8 +83,4 @@ def create_image():
|
|||||||
"""Main function for generating images."""
|
"""Main function for generating images."""
|
||||||
prompt = send_prompt_to_openwebui(user_config["comfyui"]["prompt"])
|
prompt = send_prompt_to_openwebui(user_config["comfyui"]["prompt"])
|
||||||
print(f"Generated prompt: {prompt}")
|
print(f"Generated prompt: {prompt}")
|
||||||
generate_image(str(time.time()), prompt)
|
generate_image("image", prompt)
|
||||||
|
|
||||||
|
|
||||||
# if __name__ == "__main__":
|
|
||||||
# main()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user