File size: 1,290 Bytes
c9bfa1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3260ad
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st

import os

from PIL import Image

import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.utils import array_to_img

import sys
sys.path.append(".")
from data_loader import preprocess_test_image

import warnings

warnings.filterwarnings("ignore")

@st.cache_data
def get_model():
    model_path = "models/pix2pix.keras"
    if not os.path.exists(model_path):
        model_path = "../saved_models/pix2pix/pix2pix.keras"

    with st.spinner('Loading the model...'):
        pix2pix = load_model(model_path)
    return pix2pix

st.markdown("<center><h1>ComicBooks.AI</h1></center>", unsafe_allow_html=True)
st.caption("<center>Upload your photo to see how a comic book version of yourself would look!</center>", unsafe_allow_html=True)

uploaded_file = st.file_uploader("Upload an image")

if uploaded_file is not None:
    img = Image.open(uploaded_file)
    img.save("uploaded_image.png")
    st.image(uploaded_file)
    
    img = preprocess_test_image("uploaded_image.png")
    img = tf.expand_dims(img, axis=0)
    
    pix2pix = get_model()
    with st.spinner('Processing the image...'):
        pred = array_to_img(pix2pix.predict(img)[0] * 0.5 + 0.5)
        st.image(pred)
        _ = os.system("rm uploaded_image.png")