Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from PIL import Image, ImageStat, ImageDraw
|
| 3 |
import io
|
| 4 |
|
| 5 |
# ===========================
|
| 6 |
# EURISTIC AI DETECTOR
|
| 7 |
# ===========================
|
| 8 |
def heuristic_ai_detector(image):
|
| 9 |
-
if image.size[0] < 10 or image.size[1] < 10:
|
| 10 |
-
return "Realistic", 0
|
| 11 |
stat = ImageStat.Stat(image.convert("L"))
|
| 12 |
variance = stat.var[0]
|
| 13 |
width, height = image.size
|
|
@@ -28,7 +26,7 @@ def heuristic_ai_detector(image):
|
|
| 28 |
# ===========================
|
| 29 |
def generate_heatmap(image, score):
|
| 30 |
base = image.convert("RGBA")
|
| 31 |
-
overlay = Image.new("RGBA", base.size, (255, 0, 0, int(score*2.
|
| 32 |
return Image.alpha_composite(base, overlay)
|
| 33 |
|
| 34 |
# ===========================
|
|
@@ -38,7 +36,6 @@ def check_image(image):
|
|
| 38 |
label, score = heuristic_ai_detector(image)
|
| 39 |
heatmap = generate_heatmap(image, score)
|
| 40 |
|
| 41 |
-
# Colori output box testuale
|
| 42 |
if score < 40:
|
| 43 |
color = "#4CAF50" # verde
|
| 44 |
elif score < 70:
|
|
@@ -46,25 +43,24 @@ def check_image(image):
|
|
| 46 |
else:
|
| 47 |
color = "#F44336" # rosso
|
| 48 |
|
| 49 |
-
# Testo formattato HTML
|
| 50 |
if label == "AI Generated":
|
| 51 |
explanation = f"""
|
| 52 |
-
<div style="border-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
</div>
|
| 59 |
"""
|
| 60 |
else:
|
| 61 |
explanation = f"""
|
| 62 |
-
<div style="border-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
</div>
|
| 69 |
"""
|
| 70 |
|
|
@@ -74,11 +70,14 @@ def check_image(image):
|
|
| 74 |
# GRADIO BLOCKS MODERNO
|
| 75 |
# ===========================
|
| 76 |
with gr.Blocks(css="""
|
| 77 |
-
body { background-color: #0d1117; font-family: 'Montserrat', sans-serif; color:
|
| 78 |
-
h1 { text-align:
|
| 79 |
-
h3 { text-align:
|
| 80 |
-
.gr-button { background: linear-gradient(90deg,
|
| 81 |
-
.gr-
|
|
|
|
|
|
|
|
|
|
| 82 |
""") as demo:
|
| 83 |
|
| 84 |
gr.HTML("<h1>💎 Image Trust Checker 2026</h1><h3>Verifica se le immagini sono generate da AI o realistiche</h3>")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageStat, ImageDraw
|
| 3 |
import io
|
| 4 |
|
| 5 |
# ===========================
|
| 6 |
# EURISTIC AI DETECTOR
|
| 7 |
# ===========================
|
| 8 |
def heuristic_ai_detector(image):
|
|
|
|
|
|
|
| 9 |
stat = ImageStat.Stat(image.convert("L"))
|
| 10 |
variance = stat.var[0]
|
| 11 |
width, height = image.size
|
|
|
|
| 26 |
# ===========================
|
| 27 |
def generate_heatmap(image, score):
|
| 28 |
base = image.convert("RGBA")
|
| 29 |
+
overlay = Image.new("RGBA", base.size, (255, 0, 0, int(score*2.5)))
|
| 30 |
return Image.alpha_composite(base, overlay)
|
| 31 |
|
| 32 |
# ===========================
|
|
|
|
| 36 |
label, score = heuristic_ai_detector(image)
|
| 37 |
heatmap = generate_heatmap(image, score)
|
| 38 |
|
|
|
|
| 39 |
if score < 40:
|
| 40 |
color = "#4CAF50" # verde
|
| 41 |
elif score < 70:
|
|
|
|
| 43 |
else:
|
| 44 |
color = "#F44336" # rosso
|
| 45 |
|
|
|
|
| 46 |
if label == "AI Generated":
|
| 47 |
explanation = f"""
|
| 48 |
+
<div class="result-card" style="border-left: 5px solid {color};">
|
| 49 |
+
<h2>⚠️ AI Generated Image</h2>
|
| 50 |
+
<p><b>Score AI stimato:</b> {score:.1f}%</p>
|
| 51 |
+
<p>Rumore basso / texture uniforme</p>
|
| 52 |
+
<p>Dimensioni insolite</p>
|
| 53 |
+
<p>Metadata EXIF assente</p>
|
| 54 |
</div>
|
| 55 |
"""
|
| 56 |
else:
|
| 57 |
explanation = f"""
|
| 58 |
+
<div class="result-card" style="border-left: 5px solid {color};">
|
| 59 |
+
<h2>✅ Realistic Image</h2>
|
| 60 |
+
<p><b>Score AI stimato:</b> {score:.1f}%</p>
|
| 61 |
+
<p>Rumore naturale</p>
|
| 62 |
+
<p>Dimensioni coerenti</p>
|
| 63 |
+
<p>Metadata EXIF presente</p>
|
| 64 |
</div>
|
| 65 |
"""
|
| 66 |
|
|
|
|
| 70 |
# GRADIO BLOCKS MODERNO
|
| 71 |
# ===========================
|
| 72 |
with gr.Blocks(css="""
|
| 73 |
+
body { background-color: #0d1117; font-family: 'Montserrat', sans-serif; color: #EEE; margin:0; }
|
| 74 |
+
h1 { text-align:center; font-size: 48px; color: #FFD700; margin-bottom: 5px;}
|
| 75 |
+
h3 { text-align:center; color: #CCCCCC; margin-top:0px; font-weight:normal; }
|
| 76 |
+
.gr-button { background: linear-gradient(90deg,#FFD700,#FFAA00); color:black; font-weight:bold; border-radius:10px; height:50px; font-size:18px; transition: all 0.3s ease;}
|
| 77 |
+
.gr-button:hover { transform: scale(1.05); box-shadow:0px 5px 15px rgba(255,170,0,0.6);}
|
| 78 |
+
.result-card { background-color:#161B22; border-radius:15px; padding:20px; margin-top:20px; box-shadow:0 4px 15px rgba(0,0,0,0.4); transition: transform 0.3s ease;}
|
| 79 |
+
.result-card:hover { transform: scale(1.02); }
|
| 80 |
+
.gr-box { background-color:transparent; border-radius:15px; padding:15px; }
|
| 81 |
""") as demo:
|
| 82 |
|
| 83 |
gr.HTML("<h1>💎 Image Trust Checker 2026</h1><h3>Verifica se le immagini sono generate da AI o realistiche</h3>")
|