|
import gradio as gr |
|
from PIL import Image |
|
import os |
|
import numpy as np |
|
|
|
def process_image(input_image): |
|
|
|
img_size_kb = os.path.getsize(input_image) / 1024 |
|
|
|
|
|
size = 300 |
|
if img_size_kb > 500: |
|
|
|
color = [0, 255, 0] |
|
else: |
|
|
|
color = [0, 0, 0] |
|
|
|
|
|
array = np.zeros((size, size, 3), dtype=np.uint8) |
|
array[:, :] = color |
|
|
|
return Image.fromarray(array) |
|
|
|
|
|
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() |