AdarshRavis commited on
Commit
8fa5bb5
1 Parent(s): 63a45cc

Delete app_old2.py

Browse files
Files changed (1) hide show
  1. app_old2.py +0 -57
app_old2.py DELETED
@@ -1,57 +0,0 @@
1
- from keras.models import load_model
2
- from numpy.random import randint
3
- import numpy as np
4
- import cv2
5
- from matplotlib import pyplot as plt
6
- from PIL import Image
7
- import streamlit as st
8
-
9
- def load_and_preprocess_image(image, target_shape=(256, 256)):
10
- image = np.array(image)
11
- custom_image = cv2.resize(image, target_shape)
12
- custom_image = cv2.cvtColor(custom_image, cv2.COLOR_RGB2BGR)
13
- if custom_image.max() > 1.0:
14
- custom_image = (custom_image.astype(np.float32)-127.5) / 127.50
15
- custom_image = np.expand_dims(custom_image, axis=0)
16
- return custom_image
17
-
18
- # Streamlit UI
19
- st.title("Image Processing with Keras Model")
20
-
21
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
22
-
23
-
24
- if uploaded_file is not None:
25
- # Load and preprocess image
26
- image = Image.open(uploaded_file).convert('RGB')
27
- st.image(image, caption='Original Image', use_column_width=True)
28
-
29
- custom_image = load_and_preprocess_image(image)
30
-
31
- # Define and load model
32
- model = load_model('model_016950.h5')
33
-
34
- # Generate image
35
- gen_image = model.predict(custom_image)
36
- gen_image = np.squeeze(gen_image, axis=0) # remove the batch dimension
37
- gen_image = ((gen_image + 1) * 127.5).astype(np.uint8)
38
- gen_image = cv2.cvtColor(gen_image, cv2.COLOR_BGR2RGB)
39
- gen_image_pil = Image.fromarray(gen_image)
40
- st.image(gen_image_pil, caption='Generated Image', use_column_width=True)
41
-
42
-
43
-
44
- # Plotting results
45
- fig, ax = plt.subplots(1, 2, figsize=(10, 5))
46
-
47
- ax[0].imshow(image)
48
- ax[0].set_title("Original Image")
49
- ax[0].axis('off')
50
-
51
- ax[1].imshow(gen_image_pil)
52
- ax[1].set_title("Generated Image")
53
- ax[1].axis('off')
54
-
55
- st.pyplot(fig)
56
-
57
-