File size: 2,074 Bytes
732b57d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75ed2e1
732b57d
 
 
 
 
 
75ed2e1
732b57d
 
 
5d9b5ae
75ed2e1
0740ae4
 
75ed2e1
0740ae4
 
75ed2e1
 
5d9b5ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# IMPORT LIBRARIES & FUNCTIONS
# External Libraries
import streamlit as st

# Project Functions
# - Model
from src.model.model import load_model, stylize_content_image
from src.model.utils import use_low_resource_settings, suppress_warnings

# - Data
from src.data.data import upload_image
from src.data.utils import remove_source_images

use_low_resource_settings("Yes")

suppress_warnings("Yes")

st.write("# 🖼️Neural🎨Style🖌️Transfer🖼️")

# LOAD MODEL
with st.spinner("🖌️Loading Model"):
    model = load_model()
st.success("🖌️Model Loaded")

content_image_def, style_image_def = st.columns(2)
with content_image_def:
    st.write("🖼️ Content Image: Image to style")
with style_image_def:
    st.write("🎨 Style Image: Style to transfer to content image")

content_image, style_image = st.columns(2)

# UPLOAD IMAGES
with content_image:
    ContentColumnTitle = "## 🖼️ Content Image 🖼️"
    ContentImageSelectionPrompt = "Pick a Content image"
    content_image_file = upload_image(
        ContentColumnTitle, ContentImageSelectionPrompt, "Content", "content"
    )

with style_image:
    StyleColumnTitle = "## 🎨 Style Image 🎨"
    StyleImageSelectionPrompt = "Pick a Style image"
    style_image_file = upload_image(
        StyleColumnTitle, StyleImageSelectionPrompt, "Style", "style"
    )

if None not in (content_image_file, style_image_file):
    try:
        # CLEAR IMAGES
        clear_images = st.button(
            label="🔄❌ Clear Image Cache ❌🔄",
            on_click=remove_source_images(),
        )
    except:
        pass

    # STYLIZE CONTENT IMAGE
    stylize_image = st.button("🖼️🖌️🎨 Start Neural Style Transfer 🖼️🖌️🎨")

    if stylize_image:
        final_image = stylize_content_image(model, content_image_file, style_image_file)
        st.write("# Styled Image:")
        st.image(final_image)
        try:
            remove_source_images()
        except:
            pass

else:
    st.write("Please upload content and style image to go to next step.")