sebastiansarasti commited on
Commit
883346a
·
verified ·
1 Parent(s): 1bd4eda

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +36 -0
main.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # create the model
10
+ model = ModelColorization().from_pretrained("sebastiansarasti/AutoEncoderImageColorization")
11
+
12
+ # create the streamlit app
13
+ st.title("Image Colorization App")
14
+ st.write("This is an app to colorize black and white images.")
15
+
16
+ # create a botton to upload the image
17
+ uploaded_file = st.file_uploader("Choose an image...", type="jpg")
18
+
19
+ # check if the image is uploaded
20
+ if uploaded_file is not None:
21
+ # display the image
22
+ image = Image.open(uploaded_file)
23
+ st.image(image, caption="Uploaded Image.", use_container_width=True)
24
+
25
+ # create a button to colorize the image
26
+ if st.button("Colorize"):
27
+ # process the grayscale image
28
+ image, original_size = process_gs_image(image)
29
+ # run the model
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)