Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,6 @@ def load_image(image_path, max_dim):
|
|
| 18 |
|
| 19 |
|
| 20 |
def deprocess_inception_image(img):
|
| 21 |
-
img = np.array(img).astype(np.uint8)
|
| 22 |
img = 255 * (img + 1) / 2
|
| 23 |
return np.array(img, np.uint8)
|
| 24 |
|
|
@@ -90,8 +89,8 @@ centered_text = """
|
|
| 90 |
"""
|
| 91 |
|
| 92 |
# Streamlit App
|
| 93 |
-
st.title("Deep Dream")
|
| 94 |
-
st.write("Upload an image to generate
|
| 95 |
"different effects.")
|
| 96 |
st.write("Image generation may take a while depending on the parameters chosen, kindly be patient.")
|
| 97 |
|
|
@@ -113,7 +112,7 @@ weight = st.sidebar.slider("Weight", 0.01, 0.1, 0.02, step=0.01, help="Weight fo
|
|
| 113 |
|
| 114 |
if uploaded_file is not None:
|
| 115 |
# Load and preprocess the uploaded image
|
| 116 |
-
input_image = load_image(uploaded_file, max_dim=
|
| 117 |
preprocessed_image = inception_v3.preprocess_input(input_image)
|
| 118 |
|
| 119 |
# Create Inception model and modify for deep dream
|
|
@@ -123,17 +122,15 @@ if uploaded_file is not None:
|
|
| 123 |
selected_layers = [f'mixed{i}' for i, checkbox in enumerate(layer_checkboxes, start=1) if checkbox]
|
| 124 |
dream_model = deep_dream_model(inception, selected_layers)
|
| 125 |
|
| 126 |
-
# Run gradient ascent with progress bar
|
| 127 |
progress_bar = st.progress(0.0) # Initialize progress bar
|
| 128 |
-
|
| 129 |
# Run gradient ascent
|
| 130 |
-
image_array = run_gradient_ascent(dream_model, preprocessed_image, progress_bar, epochs=epochs, steps_per_epoch=steps_per_epoch, weight=weight)
|
| 131 |
|
| 132 |
# Convert numpy arrays to PIL images
|
| 133 |
dream_pil_image = array_to_img(deprocess_inception_image(image_array))
|
| 134 |
|
| 135 |
# Display the Deep Dream image
|
| 136 |
-
st.image(dream_pil_image, caption='Deep Dream Image', width=
|
| 137 |
|
| 138 |
st.markdown("<hr>", unsafe_allow_html=True)
|
| 139 |
st.markdown(centered_text, unsafe_allow_html=True)
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def deprocess_inception_image(img):
|
|
|
|
| 21 |
img = 255 * (img + 1) / 2
|
| 22 |
return np.array(img, np.uint8)
|
| 23 |
|
|
|
|
| 89 |
"""
|
| 90 |
|
| 91 |
# Streamlit App
|
| 92 |
+
st.title("Deep Dream Streamlit App")
|
| 93 |
+
st.write("Upload an image to generate mesmerizing Deep Dream images. Adjust the parameters in the sidebar to get "
|
| 94 |
"different effects.")
|
| 95 |
st.write("Image generation may take a while depending on the parameters chosen, kindly be patient.")
|
| 96 |
|
|
|
|
| 112 |
|
| 113 |
if uploaded_file is not None:
|
| 114 |
# Load and preprocess the uploaded image
|
| 115 |
+
input_image = load_image(uploaded_file, max_dim=250)
|
| 116 |
preprocessed_image = inception_v3.preprocess_input(input_image)
|
| 117 |
|
| 118 |
# Create Inception model and modify for deep dream
|
|
|
|
| 122 |
selected_layers = [f'mixed{i}' for i, checkbox in enumerate(layer_checkboxes, start=1) if checkbox]
|
| 123 |
dream_model = deep_dream_model(inception, selected_layers)
|
| 124 |
|
|
|
|
| 125 |
progress_bar = st.progress(0.0) # Initialize progress bar
|
|
|
|
| 126 |
# Run gradient ascent
|
| 127 |
+
(image_array, progress_bar) = run_gradient_ascent(dream_model, preprocessed_image, progress_bar, epochs=epochs, steps_per_epoch=steps_per_epoch, weight=weight)
|
| 128 |
|
| 129 |
# Convert numpy arrays to PIL images
|
| 130 |
dream_pil_image = array_to_img(deprocess_inception_image(image_array))
|
| 131 |
|
| 132 |
# Display the Deep Dream image
|
| 133 |
+
st.image(dream_pil_image, caption='Deep Dream Image', width=400)
|
| 134 |
|
| 135 |
st.markdown("<hr>", unsafe_allow_html=True)
|
| 136 |
st.markdown(centered_text, unsafe_allow_html=True)
|