pix2pix v1.0
Browse filesAn example of a program that can be used
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2 as cv
|
2 |
+
from keras.utils import get_file
|
3 |
+
import numpy as np
|
4 |
+
import streamlit as st
|
5 |
+
import tensorflow as tf
|
6 |
+
from keras.models import load_model
|
7 |
+
from streamlit_drawable_canvas import st_canvas
|
8 |
+
|
9 |
+
st.title('Facades pix2pix 🏢')
|
10 |
+
|
11 |
+
drawing_mode = st.sidebar.selectbox(
|
12 |
+
"Drawing tool:", ("freedraw", "line", "rect", "circle", "transform")
|
13 |
+
)
|
14 |
+
|
15 |
+
stroke_color = st.sidebar.color_picker("Stroke color : ", "#000")
|
16 |
+
|
17 |
+
fill_color = st.sidebar.color_picker("Fill color : ", "#eee")
|
18 |
+
|
19 |
+
background_color = st.sidebar.color_picker("Background_color: ", "#fff")
|
20 |
+
|
21 |
+
stroke_width = st.sidebar.slider("Stroke width : ", 0, 25, 0)
|
22 |
+
|
23 |
+
canvas_result = st_canvas(
|
24 |
+
fill_color=fill_color,
|
25 |
+
stroke_width=stroke_width,
|
26 |
+
stroke_color=stroke_color,
|
27 |
+
background_color=background_color,
|
28 |
+
height=256,
|
29 |
+
width=256,
|
30 |
+
drawing_mode=drawing_mode,
|
31 |
+
point_display_radius=1 if drawing_mode == 'point' else 0,
|
32 |
+
key="canvas",
|
33 |
+
)
|
34 |
+
|
35 |
+
reshaped_data = np.reshape(canvas_result.image_data, (256, 256, 4))
|
36 |
+
red_channel = reshaped_data[:, :, 0]
|
37 |
+
green_channel = reshaped_data[:, :, 1]
|
38 |
+
blue_channel = reshaped_data[:, :, 2]
|
39 |
+
image = np.dstack((red_channel, green_channel, blue_channel))
|
40 |
+
|
41 |
+
resize = cv.resize(image, (256, 256))
|
42 |
+
|
43 |
+
if st.button("Generate image"):
|
44 |
+
pix2pix_model_path = get_file(
|
45 |
+
origin="https://huggingface.co/CineAI/Pix2Pix/resolve/main/pix2pix.h5",
|
46 |
+
file_hash="555576fa2ea8be3192c547a3355f4ac419ff9c2b94abcce5a2252b873055ce6b",
|
47 |
+
)
|
48 |
+
|
49 |
+
model = load_model(pix2pix_model_path)
|
50 |
+
extra_dim = np.expand_dims(resize, axis=0)
|
51 |
+
image_generated = model(extra_dim)
|
52 |
+
image_generated = (image_generated + 1) / 2.0
|
53 |
+
image_generated = tf.cast(image_generated * 255, tf.uint8)
|
54 |
+
st.image(np.squeeze(image_generated, axis=0))
|
55 |
+
|