File size: 1,109 Bytes
56a9e12
f03f961
 
 
56a9e12
f03f961
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56a9e12
f03f961
 
 
 
 
 
 
 
 
9112e74
b882389
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
from PIL import Image
import os
import numpy as np

def process_image(input_image):
    # Get image size in KB
    img_size_kb = os.path.getsize(input_image) / 1024
    
    # Create output image (300x300 square)
    size = 300
    if img_size_kb > 500:
        # Green square for large images
        color = [0, 255, 0]  # RGB for green
    else:
        # Black square for small images
        color = [0, 0, 0]  # RGB for black
    
    # Create numpy array with the specified color
    array = np.zeros((size, size, 3), dtype=np.uint8)
    array[:, :] = color
    
    return Image.fromarray(array)

# Create Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("## Image Size Checker")
    gr.Markdown("Upload an image. Output will be green if >500KB, black otherwise.")
    
    with gr.Row():
        input_image = gr.Image(type="filepath", label="Upload Image")
        output_image = gr.Image(label="Result", width=300, height=300)
    
    submit_btn = gr.Button("Check Size")
    submit_btn.click(fn=process_image, inputs=input_image, outputs=output_image)

demo.launch()