Skip to content

Commit

Permalink
added UI using streamlit
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed Jun 17, 2021
1 parent b13a60a commit 50b686f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Binary file modified __pycache__/helpers.cpython-37.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def generate_image(image_path:str):
input_image = np.array(Image.open(image_path))
H,W,C = input_image.shape
if H or W >512:
if (H or W) >=512:
img = config.custom_transform(image=input_image)['image']
else:
img = config.test_transform(image=input_image)['image']
Expand Down
58 changes: 58 additions & 0 deletions streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from streamlit import cli as stcli
import streamlit
from requests_toolbelt.multipart.encoder import MultipartEncoder
import requests
from PIL import Image
import io
import sys

def main():
streamlit.title('Enhanced Super Resolution GAN')

# fastapi endpoint
url = 'http://127.0.0.1:8000'
endpoint = '/uploadfile/'
col_1, col_2 = streamlit.beta_columns(2)
col_1.image("https://pytorch.org/assets/images/pytorch-logo.png", use_column_width=True)
col_2.image("https://images4.programmersought.com/878/c8/c8b175f9d26f422afd56a6a20285302e.png", use_column_width=True)
streamlit.write('''ESRGAN model is implemented in PyTorch.
This streamlit example uses a FastAPI service as backend.
Visit this URL at `:8000/docs` for FastAPI documentation.''') # description and instructions

image = streamlit.file_uploader('insert image') # image upload widget

@streamlit.cache
def process(image, server_url: str):

m = MultipartEncoder(
fields={'file': ('filename.jpg', image, 'image/jpeg')}
)

r = requests.post(server_url,
data=m,
headers={'Content-Type': m.content_type},
timeout=8000)

return r


if streamlit.button('Generate'):

if image == None:
streamlit.write("Insert an image!") # handle case with no image
else:
col1, col2 = streamlit.beta_columns(2)
input_image = process(image, url+endpoint)
generated_image = Image.open(io.BytesIO(input_image.content)).convert('RGB')
col1.header("Input Image")
col1.image(image, use_column_width=True)
col2.header("Output Image")
col2.image(generated_image, use_column_width=True)
# streamlit.image([image, segmented_image], width=300)

if __name__ == '__main__':
if streamlit._is_running_with_streamlit:
main()
else:
sys.argv = ["streamlit", "run", sys.argv[0]]
sys.exit(stcli.main())

0 comments on commit 50b686f

Please sign in to comment.