wildoctopus commited on
Commit
f03f961
·
verified ·
1 Parent(s): b882389

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -1,6 +1,37 @@
1
  import gradio as gr
 
 
 
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  with gr.Blocks() as demo:
4
- gr.Markdown("# Welcome to Gradio! 🎉")
 
 
 
 
 
 
 
 
5
 
6
  demo.launch()
 
1
  import gradio as gr
2
+ from PIL import Image
3
+ import os
4
+ import numpy as np
5
 
6
+ def process_image(input_image):
7
+ # Get image size in KB
8
+ img_size_kb = os.path.getsize(input_image) / 1024
9
+
10
+ # Create output image (300x300 square)
11
+ size = 300
12
+ if img_size_kb > 500:
13
+ # Green square for large images
14
+ color = [0, 255, 0] # RGB for green
15
+ else:
16
+ # Black square for small images
17
+ color = [0, 0, 0] # RGB for black
18
+
19
+ # Create numpy array with the specified color
20
+ array = np.zeros((size, size, 3), dtype=np.uint8)
21
+ array[:, :] = color
22
+
23
+ return Image.fromarray(array)
24
+
25
+ # Create Gradio interface
26
  with gr.Blocks() as demo:
27
+ gr.Markdown("## Image Size Checker")
28
+ gr.Markdown("Upload an image. Output will be green if >500KB, black otherwise.")
29
+
30
+ with gr.Row():
31
+ input_image = gr.Image(type="filepath", label="Upload Image")
32
+ output_image = gr.Image(label="Result", width=300, height=300)
33
+
34
+ submit_btn = gr.Button("Check Size")
35
+ submit_btn.click(fn=process_image, inputs=input_image, outputs=output_image)
36
 
37
  demo.launch()