File size: 1,254 Bytes
49c64a7 | 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 38 39 40 | import gradio as gr
import cv2
import numpy as np
from PIL import Image
def blur_score_from_pil(pil_img: Image.Image) -> float:
# Convert PIL -> OpenCV grayscale
img = np.array(pil_img.convert("RGB"))
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
return float(cv2.Laplacian(gray, cv2.CV_64F).var())
def check_blur(image: Image.Image, blur_threshold: float = 100.0):
if image is None:
return None, "No image provided."
score = blur_score_from_pil(image)
if score < blur_threshold:
return score, "🚫 Blurry image detected. Please re-upload a clearer image."
else:
return score, "✅ Image looks clear. Proceeding to next step."
demo = gr.Interface(
fn=check_blur,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Slider(0, 500, value=100, step=1, label="Blur Threshold (Laplacian Variance)"),
],
outputs=[
gr.Number(label="Blur Score (Laplacian Variance)"),
gr.Textbox(label="Result"),
],
title="Image Blur Checker",
description="Checks image blur using variance of the Laplacian. Lower score = blurrier image.",
)
demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True) |