Uzaiir commited on
Commit
45cae33
·
verified ·
1 Parent(s): 7fc01f5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +31 -31
src/streamlit_app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  from io import BytesIO
3
  from PIL import Image
4
- # from utils import convert_to_bw, load_colorization_model, colorize_bw_image
5
  import os
6
  os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
7
 
@@ -13,40 +13,40 @@ uploaded_file = st.sidebar.file_uploader("Upload an image", type=["jpg", "jpeg",
13
 
14
 
15
 
16
- # if uploaded_file:
17
- # # Open and convert the uploaded image to RGB format
18
- # image = Image.open(uploaded_file).convert("RGB")
19
 
20
- # option = st.sidebar.selectbox("Choose an action", ("Convert to Black & White", "Colorize Black & White"))
21
 
22
- # if st.sidebar.button("Process"):
23
- # #Convert the uploaded image to black and white
24
- # if option == "Convert to Black & White":
25
- # result_img = convert_to_bw(image)
26
- # #Colorize a black and white image using a pre-trained model
27
- # elif option == "Colorize Black & White":
28
- # with st.spinner("Colorizing..."):
29
- # net = load_colorization_model()
30
- # result_img = colorize_bw_image(image, net)
31
 
32
 
33
- # # Display both images in columns
34
- # col1, col2 = st.columns(2)
35
- # with col1:
36
- # st.image(image, caption="Original Image", use_container_width=True)
37
- # with col2:
38
- # st.image(result_img, caption="Processed Image", use_container_width=True)
39
 
40
 
41
- # # Create a buffer to store image bytes
42
- # buffer = BytesIO()
43
- # result_img.save(buffer, format="JPEG")
44
- # buffer.seek(0) # Reset cursor to the beginning
45
 
46
- # #Download Image in Jpeg
47
- # st.download_button(
48
- # label="Download Output Image",
49
- # data=buffer ,#result_img.tobytes()
50
- # file_name="output.jpeg",
51
- # mime="image/jpeg"
52
- # )
 
1
  import streamlit as st
2
  from io import BytesIO
3
  from PIL import Image
4
+ from utils import convert_to_bw, load_colorization_model, colorize_bw_image
5
  import os
6
  os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
7
 
 
13
 
14
 
15
 
16
+ if uploaded_file:
17
+ # Open and convert the uploaded image to RGB format
18
+ image = Image.open(uploaded_file).convert("RGB")
19
 
20
+ option = st.sidebar.selectbox("Choose an action", ("Convert to Black & White", "Colorize Black & White"))
21
 
22
+ if st.sidebar.button("Process"):
23
+ #Convert the uploaded image to black and white
24
+ if option == "Convert to Black & White":
25
+ result_img = convert_to_bw(image)
26
+ #Colorize a black and white image using a pre-trained model
27
+ elif option == "Colorize Black & White":
28
+ with st.spinner("Colorizing..."):
29
+ net = load_colorization_model()
30
+ result_img = colorize_bw_image(image, net)
31
 
32
 
33
+ # Display both images in columns
34
+ col1, col2 = st.columns(2)
35
+ with col1:
36
+ st.image(image, caption="Original Image", use_container_width=True)
37
+ with col2:
38
+ st.image(result_img, caption="Processed Image", use_container_width=True)
39
 
40
 
41
+ # Create a buffer to store image bytes
42
+ buffer = BytesIO()
43
+ result_img.save(buffer, format="JPEG")
44
+ buffer.seek(0) # Reset cursor to the beginning
45
 
46
+ #Download Image in Jpeg
47
+ st.download_button(
48
+ label="Download Output Image",
49
+ data=buffer ,#result_img.tobytes()
50
+ file_name="output.jpeg",
51
+ mime="image/jpeg"
52
+ )