SusiePHaltmann commited on
Commit
fb51992
·
1 Parent(s): 610fa24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -43,3 +43,27 @@ def inpaint(img, mask):
43
  Returns:
44
 
45
  The inpainted image as a 3-channel RGB numpy array. """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  Returns:
44
 
45
  The inpainted image as a 3-channel RGB numpy array. """
46
+ ## V0.2
47
+ import streamlit as st
48
+ import numpy as np
49
+ from PIL import Image
50
+ import requests
51
+ import io
52
+
53
+
54
+ st.set_option('deprecation.showfileUploaderEncoding', False)
55
+
56
+
57
+ @st.cache(allow_output_mutation=True)
58
+ def load_image(img):
59
+ im = Image.open(img)
60
+ return im
61
+
62
+
63
+ def main():
64
+
65
+ st.title("Dall-E Flow")
66
+
67
+ uploaded_file = st.file_uploader("Choose an image", type="jpg")
68
+
69
+ if uploaded_file is not None: # if user has uploaded file, display it in the app UI # along with the option to edit it # (i.e., erase portions of the image using a brush tool) # or download it after editing is complete img = load_image(uploaded_file) st.image(img, caption='Original Image', use_column_width=True) # create "Erase" button and erase brush size slider erase = st.button('Erase') brushsize = st.slider('Brush Size', 0, 100, 5, key='brush') # create "Download" button and hide it by default download = st.button('Download') download = download if not erase else None # define functions for handling mouse events def onclick(x, y): draw[int(y)-brushsize:int(y)+brushsize+1, int(x)-brushsize:int(x)+brushsize+1] \ *= 0 def ondragstart(): pass def ondragmove(): pass def ondragend(): pass # set up event handlers for when "Erase" button is clicked if erase: draw = img._numpy().copy() width, height = draw[:, :3].shape[1:] xylims=(0., width), (0., height) figtoolbar=dict(_visible=False), _onclick=onclick, _ondragstart=ondragstart(), _ondragmove=ondragmove(), _ondragend=ondragend()) pxsz=(width/height)/100*5 pltlytools="boxselect", "lassoselect", "pan", "wheelzoom", "reset" figkwargs={'layout': go .Layout(*figtoolbar)} with out: clear() show(*pltlytools)(draw[:, :3], **figkwargs)) elif download: return sendfiles([BytesIO((255*draw).astype('uint8'))], [f'dall-e-{time()}.png']) else: return None main()