nasa-sen1floods11-fastdash / fast_dash_app.py
Kedar Dabhadkar
Adapt for Fast Dash
9d30a24
raw
history blame
741 Bytes
from fast_dash import FastDash, UploadImage, Image, Upload
import PIL
import numpy as np
from app import func
import tempfile
import base64
def generate_image(input_tiff_image: Upload) -> (Image, Image):
with tempfile.NamedTemporaryFile(delete=False) as f:
contents = input_tiff_image.encode("utf8").split(b";base64,")[1]
f.write(base64.decodebytes(contents))
input_image, output_image = func(f)
# Convert numpy arrays to PIL images
input_image = PIL.Image.fromarray(np.uint8(input_image)).convert('RGB')
output_image = PIL.Image.fromarray(np.uint8(output_image)).convert('RGB')
return input_image, output_image
app = FastDash(generate_image, port=8000)
if __name__ == "__main__":
app.run()