123Sashank12 commited on
Commit
49c64a7
·
verified ·
1 Parent(s): f415bab

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+
7
+ def blur_score_from_pil(pil_img: Image.Image) -> float:
8
+ # Convert PIL -> OpenCV grayscale
9
+ img = np.array(pil_img.convert("RGB"))
10
+ gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
11
+ return float(cv2.Laplacian(gray, cv2.CV_64F).var())
12
+
13
+
14
+ def check_blur(image: Image.Image, blur_threshold: float = 100.0):
15
+ if image is None:
16
+ return None, "No image provided."
17
+
18
+ score = blur_score_from_pil(image)
19
+
20
+ if score < blur_threshold:
21
+ return score, "🚫 Blurry image detected. Please re-upload a clearer image."
22
+ else:
23
+ return score, "✅ Image looks clear. Proceeding to next step."
24
+
25
+
26
+ demo = gr.Interface(
27
+ fn=check_blur,
28
+ inputs=[
29
+ gr.Image(type="pil", label="Upload Image"),
30
+ gr.Slider(0, 500, value=100, step=1, label="Blur Threshold (Laplacian Variance)"),
31
+ ],
32
+ outputs=[
33
+ gr.Number(label="Blur Score (Laplacian Variance)"),
34
+ gr.Textbox(label="Result"),
35
+ ],
36
+ title="Image Blur Checker",
37
+ description="Checks image blur using variance of the Laplacian. Lower score = blurrier image.",
38
+ )
39
+
40
+ demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ opencv-python-headless
3
+ pillow
4
+ numpy