mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-04-28 11:13: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/
|
||||
dist/
|
||||
user_config.cfg
|
||||
Dockerfile
|
||||
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"
|
||||
|
||||
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('/')
|
||||
def index():
|
||||
latest_image = get_latest_image()
|
||||
return render_template("index.html", image=latest_image)
|
||||
# latest_image = get_latest_image()
|
||||
return render_template("index.html", image="./image.png")
|
||||
|
||||
@app.route('/images/<filename>')
|
||||
def images(filename):
|
||||
@ -32,4 +23,5 @@ def create():
|
||||
|
||||
if __name__ == '__main__':
|
||||
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 litellm
|
||||
import time
|
||||
|
||||
from datetime import datetime
|
||||
import os
|
||||
|
||||
from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper
|
||||
|
||||
@ -19,6 +18,20 @@ except KeyError as e:
|
||||
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):
|
||||
response = litellm.completion(
|
||||
api_base=user_config["openwebui"]["base_url"],
|
||||
@ -55,6 +68,7 @@ def generate_image(file_name, comfy_prompt):
|
||||
# Queue your workflow for completion
|
||||
logging.debug(f"Generating image: {file_name}")
|
||||
results = api.queue_and_wait_images(wf, "Save Image")
|
||||
rename_image()
|
||||
for filename, image_data in results.items():
|
||||
with open(
|
||||
user_config["comfyui"]["output_dir"] + file_name + ".png", "wb+"
|
||||
@ -69,8 +83,4 @@ def create_image():
|
||||
"""Main function for generating images."""
|
||||
prompt = send_prompt_to_openwebui(user_config["comfyui"]["prompt"])
|
||||
print(f"Generated prompt: {prompt}")
|
||||
generate_image(str(time.time()), prompt)
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# main()
|
||||
generate_image("image", prompt)
|
||||
|
Loading…
x
Reference in New Issue
Block a user