Update app.py
Browse files
app.py
CHANGED
@@ -623,24 +623,79 @@ def run_inference(process_id, input_image, upscale_factor, seed, num_inference_s
|
|
623 |
app.config['image_outputs'][process_id] = image_base64
|
624 |
logger.info("Inference completed for process_id: %s", process_id)
|
625 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
626 |
@app.route('/infer', methods=['POST'])
|
627 |
def infer():
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
634 |
|
635 |
# Randomize seed if specified
|
636 |
if randomize_seed:
|
637 |
seed = random.randint(0, MAX_SEED)
|
638 |
logger.info("Seed randomized to: %d", seed)
|
639 |
|
640 |
-
# Load and process the input image
|
641 |
-
input_image_data = base64.b64decode(data['input_image'])
|
642 |
-
input_image = Image.open(io.BytesIO(input_image_data))
|
643 |
-
|
644 |
# Create a unique process ID for this request
|
645 |
process_id = str(random.randint(1000, 9999))
|
646 |
logger.info("Process started with process_id: %s", process_id)
|
@@ -657,6 +712,7 @@ def infer():
|
|
657 |
"message": "Processing started"
|
658 |
})
|
659 |
|
|
|
660 |
# Modify status endpoint to receive process_id in request body
|
661 |
@app.route('/status', methods=['POST'])
|
662 |
def status():
|
|
|
623 |
app.config['image_outputs'][process_id] = image_base64
|
624 |
logger.info("Inference completed for process_id: %s", process_id)
|
625 |
|
626 |
+
# @app.route('/infer', methods=['POST'])
|
627 |
+
# def infer():
|
628 |
+
# data = request.json
|
629 |
+
# seed = data.get("seed", 42)
|
630 |
+
# randomize_seed = data.get("randomize_seed", True)
|
631 |
+
# num_inference_steps = data.get("num_inference_steps", 28)
|
632 |
+
# upscale_factor = data.get("upscale_factor", 4)
|
633 |
+
# controlnet_conditioning_scale = data.get("controlnet_conditioning_scale", 0.6)
|
634 |
+
|
635 |
+
# # Randomize seed if specified
|
636 |
+
# if randomize_seed:
|
637 |
+
# seed = random.randint(0, MAX_SEED)
|
638 |
+
# logger.info("Seed randomized to: %d", seed)
|
639 |
+
|
640 |
+
# # Load and process the input image
|
641 |
+
# input_image_data = base64.b64decode(data['input_image'])
|
642 |
+
# input_image = Image.open(io.BytesIO(input_image_data))
|
643 |
+
|
644 |
+
# # Create a unique process ID for this request
|
645 |
+
# process_id = str(random.randint(1000, 9999))
|
646 |
+
# logger.info("Process started with process_id: %s", process_id)
|
647 |
+
|
648 |
+
# # Set the status to 'in_progress'
|
649 |
+
# app.config['image_outputs'][process_id] = None
|
650 |
+
|
651 |
+
# # Run the inference in a separate thread
|
652 |
+
# executor.submit(run_inference, process_id, input_image, upscale_factor, seed, num_inference_steps, controlnet_conditioning_scale)
|
653 |
+
|
654 |
+
# # Return the process ID
|
655 |
+
# return jsonify({
|
656 |
+
# "process_id": process_id,
|
657 |
+
# "message": "Processing started"
|
658 |
+
# })
|
659 |
+
|
660 |
@app.route('/infer', methods=['POST'])
|
661 |
def infer():
|
662 |
+
# Check if the file was provided in the form-data
|
663 |
+
if 'input_image' not in request.files:
|
664 |
+
logger.error("No image file provided in request.")
|
665 |
+
return jsonify({
|
666 |
+
"status": "error",
|
667 |
+
"message": "No input_image file provided"
|
668 |
+
}), 400
|
669 |
+
|
670 |
+
# Get the uploaded image file from the request
|
671 |
+
file = request.files['input_image']
|
672 |
+
|
673 |
+
# Check if a file was uploaded
|
674 |
+
if file.filename == '':
|
675 |
+
logger.error("No selected file in form-data.")
|
676 |
+
return jsonify({
|
677 |
+
"status": "error",
|
678 |
+
"message": "No selected file"
|
679 |
+
}), 400
|
680 |
+
|
681 |
+
# Convert the image to Base64 for internal processing
|
682 |
+
input_image = Image.open(file)
|
683 |
+
buffered = io.BytesIO()
|
684 |
+
input_image.save(buffered, format="JPEG")
|
685 |
+
#input_image_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
686 |
+
|
687 |
+
# Retrieve additional parameters from the request (if any)
|
688 |
+
seed = request.form.get("seed", 42, type=int)
|
689 |
+
randomize_seed = request.form.get("randomize_seed", 'true').lower() == 'true'
|
690 |
+
num_inference_steps = request.form.get("num_inference_steps", 28, type=int)
|
691 |
+
upscale_factor = request.form.get("upscale_factor", 4, type=int)
|
692 |
+
controlnet_conditioning_scale = request.form.get("controlnet_conditioning_scale", 0.6, type=float)
|
693 |
|
694 |
# Randomize seed if specified
|
695 |
if randomize_seed:
|
696 |
seed = random.randint(0, MAX_SEED)
|
697 |
logger.info("Seed randomized to: %d", seed)
|
698 |
|
|
|
|
|
|
|
|
|
699 |
# Create a unique process ID for this request
|
700 |
process_id = str(random.randint(1000, 9999))
|
701 |
logger.info("Process started with process_id: %s", process_id)
|
|
|
712 |
"message": "Processing started"
|
713 |
})
|
714 |
|
715 |
+
|
716 |
# Modify status endpoint to receive process_id in request body
|
717 |
@app.route('/status', methods=['POST'])
|
718 |
def status():
|