|
import gradio as gr |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
modelo = tf.keras.models.load_model('combinado.h5') |
|
|
|
|
|
def predict(image): |
|
|
|
image = image.resize((32, 32)) |
|
|
|
|
|
img_ar = np.asarray(image) / 255.0 |
|
img_ar_rs1 = img_ar.reshape(-1, 32, 32, 3) |
|
|
|
|
|
pred = modelo.predict(img_ar_rs1)[0][0] |
|
|
|
|
|
porcentaje = pred * 100 |
|
|
|
|
|
if pred > 0.6: |
|
return f"La imagen es Real con un {porcentaje:.2f}% de confianza." |
|
else: |
|
return f"La imagen est谩 generada por IA con un {100 - porcentaje:.2f}% de confianza." |
|
|
|
|
|
interfaz = gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(type="pil", label="Carga tu imagen"), |
|
outputs=gr.Textbox(label="Resultado de la predicci贸n"), |
|
title="DetectAI ", |
|
description="Una aplicaci贸n que identifica las im谩genes generadas por Inteligencia Artificial.", |
|
examples=["Jarulis.jpg"], |
|
theme="compact", |
|
allow_flagging="never", |
|
live=False, |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interfaz.launch(share=True) |
|
|
|
|
|
|
|
|
|
|