From 7c7daf8ade6bb4ccf960c02893f8a892294d59b1 Mon Sep 17 00:00:00 2001 From: blessedcoolant Date: Fri, 25 Mar 2022 13:49:56 +1300 Subject: [PATCH] Bug fixes Fixed a few bugs from previous patch. - Removed default value for --input tag. It was causing the front end to trigger a request and throw an error when there was no input given. - Added a check to see if input is provided or not - Converted the new hook to Typescript and added necessary types. - Rebuilt to update to current changes. --- .../{useInputImage.js => useInputImage.tsx} | 2 +- main.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) rename lama_cleaner/app/src/components/hooks/{useInputImage.js => useInputImage.tsx} (89%) diff --git a/lama_cleaner/app/src/components/hooks/useInputImage.js b/lama_cleaner/app/src/components/hooks/useInputImage.tsx similarity index 89% rename from lama_cleaner/app/src/components/hooks/useInputImage.js rename to lama_cleaner/app/src/components/hooks/useInputImage.tsx index 0c566f1..465f5e4 100644 --- a/lama_cleaner/app/src/components/hooks/useInputImage.js +++ b/lama_cleaner/app/src/components/hooks/useInputImage.tsx @@ -1,7 +1,7 @@ import { useCallback, useEffect, useState } from 'react' export default function useInputImage() { - const [inputImage, setInputImage] = useState() + const [inputImage, setInputImage] = useState() const fetchInputImage = useCallback(() => { fetch('/inputimage') diff --git a/main.py b/main.py index ed26c47..0ede27b 100644 --- a/main.py +++ b/main.py @@ -101,22 +101,21 @@ def index(): @app.route('/inputimage') def set_input_photo(): - filename = os.path.join(os.path.dirname(__file__), input_image) - if (os.path.exists(filename)): - if (imghdr.what(filename) is not None): - with open(filename, 'rb') as f: - byte_im = f.read() - return send_file(io.BytesIO(byte_im), mimetype='image/jpeg') - else: - return 'Invalid Input' + if input_image: + input_file = os.path.join(os.path.dirname(__file__), input_image) + if (os.path.exists(input_file)): # Check if file exists + if (imghdr.what(input_file) is not None): # Check if file is image + with open(input_file, 'rb') as f: + image_in_bytes = f.read() + return send_file(io.BytesIO(image_in_bytes), mimetype='image/jpeg') else: - return 'Invalid Input' + return 'No Input Image' def get_args_parser(): parser = argparse.ArgumentParser() parser.add_argument( - "--input", default='', type=str, help="Path to image you want to load by default") + "--input", type=str, help="Path to image you want to load by default") parser.add_argument("--port", default=8080, type=int) parser.add_argument("--model", default="lama", choices=["lama", "ldm"]) parser.add_argument("--crop-trigger-size", default=[2042, 2042], nargs=2, type=int,