AamerAkhter commited on
Commit
93d6253
·
verified ·
1 Parent(s): 50f9740

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -5,23 +5,24 @@ from PIL import Image
5
 
6
  st.title("Image to Grayscale Converter")
7
 
8
- # File uploader for image input
9
  uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
10
 
11
  if uploaded_file is not None:
12
- # Open the image using PIL
13
  image = Image.open(uploaded_file)
14
-
15
- # Convert the image to a format OpenCV can use (numpy array)
16
  image_np = np.array(image)
17
 
18
- # Convert to grayscale using OpenCV
19
  gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
20
 
21
- # Display original image
22
- st.subheader("Original Image")
23
- st.image(image, use_column_width=True)
 
 
 
24
 
25
- # Display grayscale image
26
- st.subheader("Grayscale Image")
27
- st.image(gray_image, use_column_width=True, clamp=True, channels="GRAY")
 
5
 
6
  st.title("Image to Grayscale Converter")
7
 
8
+ # File uploader
9
  uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
10
 
11
  if uploaded_file is not None:
12
+ # Load image with PIL and convert to numpy array
13
  image = Image.open(uploaded_file)
 
 
14
  image_np = np.array(image)
15
 
16
+ # Convert to grayscale
17
  gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
18
 
19
+ # Display side-by-side images
20
+ col1, col2 = st.columns(2)
21
+
22
+ with col1:
23
+ st.subheader("Original")
24
+ st.image(image, width=250)
25
 
26
+ with col2:
27
+ st.subheader("Grayscale")
28
+ st.image(gray_image, width=250, clamp=True, channels="GRAY")