Prashanthsrn commited on
Commit
e9d237d
·
verified ·
1 Parent(s): 94deaa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -15
app.py CHANGED
@@ -1,20 +1,32 @@
1
- import streamlit as st
2
  from PIL import Image
3
  import numpy as np
4
 
5
- def main():
6
- st.title("Simple Image Uploader")
7
- st.write("Upload an image to display it.")
 
 
 
 
 
 
 
 
 
 
8
 
9
- uploaded_file = st.file_uploader("Choose an image", type=['png', 'jpg', 'jpeg'])
 
 
 
 
 
 
 
 
 
 
10
 
11
- if uploaded_file is not None:
12
- image = Image.open(uploaded_file)
13
- st.image(image, caption='Uploaded Image', use_column_width=True)
14
-
15
- # Display image information
16
- st.write(f"Image size: {image.size}")
17
- st.write(f"Image format: {image.format}")
18
-
19
- if __name__ == "__main__":
20
- main()
 
1
+ import gradio as gr
2
  from PIL import Image
3
  import numpy as np
4
 
5
+ def process_image(image):
6
+ if image is None:
7
+ return None
8
+
9
+ # Convert to numpy array if it's a PIL Image
10
+ if isinstance(image, Image.Image):
11
+ image = np.array(image)
12
+
13
+ # Display image information
14
+ height, width = image.shape[:2]
15
+ info = f"Image size: {width}x{height}"
16
+
17
+ return image, info
18
 
19
+ # Define the Gradio interface
20
+ iface = gr.Interface(
21
+ fn=process_image,
22
+ inputs=gr.Image(type="pil"),
23
+ outputs=[
24
+ gr.Image(type="numpy", label="Uploaded Image"),
25
+ gr.Textbox(label="Image Information")
26
+ ],
27
+ title="Simple Image Uploader",
28
+ description="Upload an image to display it and show basic information."
29
+ )
30
 
31
+ # Launch the interface
32
+ iface.launch()