#import tensorflow_hub as hub import gradio as gr import tensorflow as tf # Load the model model = tf.keras.models.load_model('keras_model.h5') # Preprocess the image def preprocess_image(image): resized_image = tf.image.resize(image, [224, 224]) normalized_image = resized_image / 255.0 return normalized_image # Function to detect fake images using the model 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 # Gradio Interface iface = gr.Interface( fn=detect_fake_image, inputs="image", outputs="text", title="Fake Image Detector" ) # Launch the interface iface.launch()