Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,6 @@ import base64
|
|
| 15 |
from flask import Flask, request, jsonify
|
| 16 |
from concurrent.futures import ThreadPoolExecutor
|
| 17 |
from flask_cors import CORS
|
| 18 |
-
from tqdm import tqdm
|
| 19 |
|
| 20 |
# Configure logging
|
| 21 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -69,25 +68,25 @@ else:
|
|
| 69 |
logger.info("Hugging Face token: %s", huggingface_token)
|
| 70 |
|
| 71 |
# Download model using snapshot_download
|
| 72 |
-
|
| 73 |
model_path = snapshot_download(
|
| 74 |
repo_id="black-forest-labs/FLUX.1-dev",
|
| 75 |
repo_type="model",
|
| 76 |
ignore_patterns=["*.md", "*..gitattributes"],
|
| 77 |
local_dir="FLUX.1-dev",
|
| 78 |
token=huggingface_token)
|
| 79 |
-
|
| 80 |
|
| 81 |
# Load pipeline
|
| 82 |
logger.info('Loading ControlNet model.')
|
| 83 |
-
|
| 84 |
controlnet = FluxControlNetModel.from_pretrained(
|
| 85 |
"jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
|
| 86 |
).to(device)
|
| 87 |
logger.info("ControlNet model loaded successfully.")
|
| 88 |
|
| 89 |
logger.info('Loading pipeline.')
|
| 90 |
-
|
| 91 |
pipe = FluxControlNetPipeline.from_pretrained(
|
| 92 |
model_path, controlnet=controlnet, torch_dtype=torch.bfloat16
|
| 93 |
).to(device)
|
|
@@ -157,40 +156,6 @@ def run_inference(process_id, input_image, upscale_factor, seed, num_inference_s
|
|
| 157 |
app.config['image_outputs'][process_id] = image_base64
|
| 158 |
logger.info("Inference completed for process_id: %s", process_id)
|
| 159 |
|
| 160 |
-
# @app.route('/infer', methods=['POST'])
|
| 161 |
-
# def infer():
|
| 162 |
-
# data = request.json
|
| 163 |
-
# seed = data.get("seed", 42)
|
| 164 |
-
# randomize_seed = data.get("randomize_seed", True)
|
| 165 |
-
# num_inference_steps = data.get("num_inference_steps", 28)
|
| 166 |
-
# upscale_factor = data.get("upscale_factor", 4)
|
| 167 |
-
# controlnet_conditioning_scale = data.get("controlnet_conditioning_scale", 0.6)
|
| 168 |
-
|
| 169 |
-
# # Randomize seed if specified
|
| 170 |
-
# if randomize_seed:
|
| 171 |
-
# seed = random.randint(0, MAX_SEED)
|
| 172 |
-
# logger.info("Seed randomized to: %d", seed)
|
| 173 |
-
|
| 174 |
-
# # Load and process the input image
|
| 175 |
-
# input_image_data = base64.b64decode(data['input_image'])
|
| 176 |
-
# input_image = Image.open(io.BytesIO(input_image_data))
|
| 177 |
-
|
| 178 |
-
# # Create a unique process ID for this request
|
| 179 |
-
# process_id = str(random.randint(1000, 9999))
|
| 180 |
-
# logger.info("Process started with process_id: %s", process_id)
|
| 181 |
-
|
| 182 |
-
# # Set the status to 'in_progress'
|
| 183 |
-
# app.config['image_outputs'][process_id] = None
|
| 184 |
-
|
| 185 |
-
# # Run the inference in a separate thread
|
| 186 |
-
# executor.submit(run_inference, process_id, input_image, upscale_factor, seed, num_inference_steps, controlnet_conditioning_scale)
|
| 187 |
-
|
| 188 |
-
# # Return the process ID
|
| 189 |
-
# return jsonify({
|
| 190 |
-
# "process_id": process_id,
|
| 191 |
-
# "message": "Processing started"
|
| 192 |
-
# })
|
| 193 |
-
|
| 194 |
@app.route('/infer', methods=['POST'])
|
| 195 |
def infer():
|
| 196 |
# Check if the file was provided in the form-data
|
|
@@ -216,7 +181,6 @@ def infer():
|
|
| 216 |
input_image = Image.open(file)
|
| 217 |
buffered = io.BytesIO()
|
| 218 |
input_image.save(buffered, format="JPEG")
|
| 219 |
-
#input_image_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 220 |
|
| 221 |
# Retrieve additional parameters from the request (if any)
|
| 222 |
seed = request.form.get("seed", 42, type=int)
|
|
|
|
| 15 |
from flask import Flask, request, jsonify
|
| 16 |
from concurrent.futures import ThreadPoolExecutor
|
| 17 |
from flask_cors import CORS
|
|
|
|
| 18 |
|
| 19 |
# Configure logging
|
| 20 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 68 |
logger.info("Hugging Face token: %s", huggingface_token)
|
| 69 |
|
| 70 |
# Download model using snapshot_download
|
| 71 |
+
|
| 72 |
model_path = snapshot_download(
|
| 73 |
repo_id="black-forest-labs/FLUX.1-dev",
|
| 74 |
repo_type="model",
|
| 75 |
ignore_patterns=["*.md", "*..gitattributes"],
|
| 76 |
local_dir="FLUX.1-dev",
|
| 77 |
token=huggingface_token)
|
| 78 |
+
logger.info("Model downloaded to: %s", model_path)
|
| 79 |
|
| 80 |
# Load pipeline
|
| 81 |
logger.info('Loading ControlNet model.')
|
| 82 |
+
|
| 83 |
controlnet = FluxControlNetModel.from_pretrained(
|
| 84 |
"jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
|
| 85 |
).to(device)
|
| 86 |
logger.info("ControlNet model loaded successfully.")
|
| 87 |
|
| 88 |
logger.info('Loading pipeline.')
|
| 89 |
+
|
| 90 |
pipe = FluxControlNetPipeline.from_pretrained(
|
| 91 |
model_path, controlnet=controlnet, torch_dtype=torch.bfloat16
|
| 92 |
).to(device)
|
|
|
|
| 156 |
app.config['image_outputs'][process_id] = image_base64
|
| 157 |
logger.info("Inference completed for process_id: %s", process_id)
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
@app.route('/infer', methods=['POST'])
|
| 160 |
def infer():
|
| 161 |
# Check if the file was provided in the form-data
|
|
|
|
| 181 |
input_image = Image.open(file)
|
| 182 |
buffered = io.BytesIO()
|
| 183 |
input_image.save(buffered, format="JPEG")
|
|
|
|
| 184 |
|
| 185 |
# Retrieve additional parameters from the request (if any)
|
| 186 |
seed = request.form.get("seed", 42, type=int)
|