Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,110 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
-
|
| 5 |
from model import ModelColorization
|
| 6 |
-
|
| 7 |
from utils import process_gs_image, inverse_transform_cs
|
| 8 |
|
| 9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
model = ModelColorization().from_pretrained("sebastiansarasti/AutoEncoderImageColorization")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
st.
|
| 14 |
-
st.
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
if uploaded_file is not None:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
model.eval()
|
| 31 |
-
with torch.no_grad():
|
| 32 |
-
result = model(image)
|
| 33 |
-
# colorize the image
|
| 34 |
-
colorized_image = inverse_transform_cs(result.squeeze(0), original_size)
|
| 35 |
-
# display the colorized image
|
| 36 |
-
st.image(colorized_image, caption="Colorized Image.", use_container_width=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
|
|
|
| 4 |
from model import ModelColorization
|
|
|
|
| 5 |
from utils import process_gs_image, inverse_transform_cs
|
| 6 |
|
| 7 |
+
# Custom CSS for styling
|
| 8 |
+
st.markdown(
|
| 9 |
+
"""
|
| 10 |
+
<style>
|
| 11 |
+
.main {
|
| 12 |
+
background-color: #f9f9f9;
|
| 13 |
+
}
|
| 14 |
+
.title {
|
| 15 |
+
color: #2a3f5f;
|
| 16 |
+
font-size: 2.5em;
|
| 17 |
+
text-align: center;
|
| 18 |
+
margin-bottom: 0.5em;
|
| 19 |
+
}
|
| 20 |
+
.subheader {
|
| 21 |
+
color: #5a5a5a;
|
| 22 |
+
font-size: 1.1em;
|
| 23 |
+
text-align: center;
|
| 24 |
+
margin-bottom: 2em;
|
| 25 |
+
}
|
| 26 |
+
.upload-box {
|
| 27 |
+
background-color: #ffffff;
|
| 28 |
+
border-radius: 10px;
|
| 29 |
+
padding: 2em;
|
| 30 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 31 |
+
margin-bottom: 2em;
|
| 32 |
+
}
|
| 33 |
+
.result-box {
|
| 34 |
+
background-color: #ffffff;
|
| 35 |
+
border-radius: 10px;
|
| 36 |
+
padding: 2em;
|
| 37 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 38 |
+
margin-top: 2em;
|
| 39 |
+
}
|
| 40 |
+
.stButton>button {
|
| 41 |
+
background-color: #4CAF50;
|
| 42 |
+
color: white;
|
| 43 |
+
border-radius: 5px;
|
| 44 |
+
padding: 0.5em 1em;
|
| 45 |
+
font-size: 1em;
|
| 46 |
+
width: 100%;
|
| 47 |
+
}
|
| 48 |
+
.stButton>button:hover {
|
| 49 |
+
background-color: #45a049;
|
| 50 |
+
}
|
| 51 |
+
.group-banner {
|
| 52 |
+
text-align: center;
|
| 53 |
+
font-size: 0.9em;
|
| 54 |
+
color: #777777;
|
| 55 |
+
margin-top: 2em;
|
| 56 |
+
}
|
| 57 |
+
</style>
|
| 58 |
+
""",
|
| 59 |
+
unsafe_allow_html=True
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Load model
|
| 63 |
model = ModelColorization().from_pretrained("sebastiansarasti/AutoEncoderImageColorization")
|
| 64 |
|
| 65 |
+
# App header
|
| 66 |
+
st.markdown('<p class="title">🎨 Neural Image Colorizer</p>', unsafe_allow_html=True)
|
| 67 |
+
st.markdown('<p class="subheader">Bring black & white photos to life with AI</p>', unsafe_allow_html=True)
|
| 68 |
|
| 69 |
+
# Upload section
|
| 70 |
+
with st.container():
|
| 71 |
+
st.markdown("### 📤 Upload Your Image")
|
| 72 |
+
uploaded_file = st.file_uploader(
|
| 73 |
+
"Choose a black & white photo...",
|
| 74 |
+
type=["jpg", "jpeg", "png"],
|
| 75 |
+
label_visibility="collapsed"
|
| 76 |
+
)
|
| 77 |
|
| 78 |
+
# Processing section
|
| 79 |
if uploaded_file is not None:
|
| 80 |
+
with st.container():
|
| 81 |
+
col1, col2 = st.columns(2)
|
| 82 |
+
with col1:
|
| 83 |
+
st.markdown("### ⬆ Original")
|
| 84 |
+
original_img = Image.open(uploaded_file)
|
| 85 |
+
st.image(original_img, use_column_width=True)
|
| 86 |
+
|
| 87 |
+
with col2:
|
| 88 |
+
st.markdown("### 🎨 Colorized")
|
| 89 |
+
if st.button("✨ Colorize Image", type="primary"):
|
| 90 |
+
with st.spinner("Colorizing your image..."):
|
| 91 |
+
# Process image
|
| 92 |
+
image, original_size = process_gs_image(original_img)
|
| 93 |
+
|
| 94 |
+
# Run model
|
| 95 |
+
model.eval()
|
| 96 |
+
with torch.no_grad():
|
| 97 |
+
result = model(image)
|
| 98 |
+
|
| 99 |
+
# Get colorized image
|
| 100 |
+
colorized_image = inverse_transform_cs(result.squeeze(0), original_size)
|
| 101 |
+
|
| 102 |
+
# Display result
|
| 103 |
+
st.image(colorized_image, use_column_width=True)
|
| 104 |
+
st.success("Colorization complete!")
|
| 105 |
|
| 106 |
+
# Footer
|
| 107 |
+
st.markdown(
|
| 108 |
+
'<p class="group-banner">Developed with ❤️ by Group 9 | Computer Vision Project</p>',
|
| 109 |
+
unsafe_allow_html=True
|
| 110 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|