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.
This commit is contained in:
blessedcoolant 2022-03-25 13:49:56 +13:00
parent a2d7851a40
commit 7c7daf8ade
2 changed files with 10 additions and 11 deletions

View File

@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
export default function useInputImage() { export default function useInputImage() {
const [inputImage, setInputImage] = useState() const [inputImage, setInputImage] = useState<File>()
const fetchInputImage = useCallback(() => { const fetchInputImage = useCallback(() => {
fetch('/inputimage') fetch('/inputimage')

19
main.py
View File

@ -101,22 +101,21 @@ def index():
@app.route('/inputimage') @app.route('/inputimage')
def set_input_photo(): def set_input_photo():
filename = os.path.join(os.path.dirname(__file__), input_image) if input_image:
if (os.path.exists(filename)): input_file = os.path.join(os.path.dirname(__file__), input_image)
if (imghdr.what(filename) is not None): if (os.path.exists(input_file)): # Check if file exists
with open(filename, 'rb') as f: if (imghdr.what(input_file) is not None): # Check if file is image
byte_im = f.read() with open(input_file, 'rb') as f:
return send_file(io.BytesIO(byte_im), mimetype='image/jpeg') image_in_bytes = f.read()
return send_file(io.BytesIO(image_in_bytes), mimetype='image/jpeg')
else: else:
return 'Invalid Input' return 'No Input Image'
else:
return 'Invalid Input'
def get_args_parser(): def get_args_parser():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( 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("--port", default=8080, type=int)
parser.add_argument("--model", default="lama", choices=["lama", "ldm"]) parser.add_argument("--model", default="lama", choices=["lama", "ldm"])
parser.add_argument("--crop-trigger-size", default=[2042, 2042], nargs=2, type=int, parser.add_argument("--crop-trigger-size", default=[2042, 2042], nargs=2, type=int,