|
|
|
|
|
|
|
import gradio as gr |
|
import tensorflow as tf |
|
|
|
|
|
model = tf.keras.models.load_model('keras_model.h5') |
|
|
|
|
|
def preprocess_image(image): |
|
resized_image = tf.image.resize(image, [224, 224]) |
|
normalized_image = resized_image / 255.0 |
|
return normalized_image |
|
|
|
|
|
def detect_fake_image(image): |
|
processed_image = preprocess_image(image) |
|
prediction = model.predict(tf.expand_dims(processed_image, 0)) |
|
percentage = prediction[0][0] * 100 |
|
if percentage > 50: |
|
result = f"Real with {percentage}% confidence" |
|
else: |
|
result = f"Fake with {100 - percentage}% confidence" |
|
return result |
|
|
|
|
|
iface = gr.Interface( |
|
fn=detect_fake_image, |
|
inputs="image", |
|
outputs="text", |
|
title="Fake Image Detector" |
|
) |
|
|
|
|
|
iface.launch() |