Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,41 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Cargamos un modelo ligero de clasificaci贸n
|
| 6 |
+
classifier = pipeline(
|
| 7 |
+
"image-classification",
|
| 8 |
+
model="umm-maybe/ai-image-detector",
|
| 9 |
+
)
|
| 10 |
|
| 11 |
+
def predict(image):
|
| 12 |
+
# Convertir a formato PIL
|
| 13 |
+
image = Image.fromarray(image)
|
| 14 |
+
|
| 15 |
+
# Ejecutar predicci贸n
|
| 16 |
+
outputs = classifier(image)
|
| 17 |
+
|
| 18 |
+
# Ordenamos por confianza
|
| 19 |
+
outputs = sorted(outputs, key=lambda x: x["score"], reverse=True)
|
| 20 |
+
|
| 21 |
+
label = outputs[0]["label"]
|
| 22 |
+
score = outputs[0]["score"]
|
| 23 |
+
|
| 24 |
+
# Formato de respuesta
|
| 25 |
+
if "ai" in label.lower():
|
| 26 |
+
result = f"馃 Imagen generada por IA\nConfianza: {score:.2%}"
|
| 27 |
+
else:
|
| 28 |
+
result = f"馃摲 Imagen real\nConfianza: {score:.2%}"
|
| 29 |
+
|
| 30 |
+
return result
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=predict,
|
| 35 |
+
inputs=gr.Image(type="numpy"),
|
| 36 |
+
outputs="text",
|
| 37 |
+
title="Detector de Im谩genes IA",
|
| 38 |
+
description="Sube una imagen y detecta si es real o generada por IA.",
|
| 39 |
+
)
|
| 40 |
|
| 41 |
demo.launch()
|