Essa20001 commited on
Commit
5bb2dd4
·
verified ·
1 Parent(s): db3f1a9

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +35 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+ from io import BytesIO
6
+
7
+ st.title("Colorize black and white image using an AI model trained on Flickr images with the Pix2pix architecture.")
8
+ image = st.file_uploader("Upload an image", type=["jpg", "png","jpeg"])
9
+ model = tf.keras.models.load_model('generator_color.keras')
10
+
11
+ if image :
12
+ button = st.button("Colore")
13
+ image = Image.open(image)
14
+ image = image.convert("L")
15
+ image = image.resize((128,128))
16
+ image = np.array(image)
17
+ if button:
18
+ image = image - 127.5
19
+ image = image / 127.5
20
+ image.shape = (1,128,128,1)
21
+
22
+ result = model(image,training = True)
23
+ result = (result * 127.5) + 127.5
24
+ numpy_array = np.array(result.numpy()[0] , dtype=np.uint8)
25
+ pillow_image = Image.fromarray(numpy_array)
26
+ output_path = "output_image.jpg"
27
+ pillow_image.save(output_path)
28
+ st.image([output_path], caption='Colored Image', use_column_width=True)
29
+ st.download_button(
30
+ label="Download Stylized Image",
31
+ data=BytesIO(numpy_array.tobytes()),
32
+ file_name="output_image.jpg",
33
+ key="download_button",
34
+ help="Click to download the colored image.",
35
+ )
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ Pillow==9.4.0
2
+ streamlit==1.31.1
3
+ tensorflow==2.15.0
4
+ numpy==1.25.2