import tensorflow as tf import keras keras.config.enable_unsafe_deserialization() # Then load your model as usual: import gradio as gr import numpy as np import tensorflow as tf from tensorflow.keras.models import load_model from tensorflow.keras.preprocessing.image import img_to_array import joblib import cv2 from huggingface_hub import hf_hub_download import tensorflow as tf model_path = hf_hub_download( repo_id="abdelac/FakeImageModelKeras", filename="feature_extractor.h5" ) feature_extractor = load_model(model_path, compile=False, safe_mode=False) #feature_extractor = tf.keras.models.load_model(model_path) print("Model loaded successfully!") # Load the models first model jjjff fkfkfkfkfkfk # feature_extractor = load_model("feature_extractor.keras", safe_mode=False) classifier = joblib.load("adaboost_model.pkl") label_encoder = joblib.load("label_encoder.pkl") S = 299 # Your image size def predict(input_img): # Preprocess img = cv2.resize(input_img, (S, S)) img = img.astype("float32") / 255.0 img = np.expand_dims(img, axis=0) # Extract Features features = feature_extractor.predict(img) features = features.reshape(1, -1) # Classify prediction_idx = classifier.predict(features)[0] # Logic from your code if prediction_idx == 0: return "Fake or Dog" else: return "Real or Cat" # Create Gradio UI interface = gr.Interface( fn=predict, inputs=gr.Image(), outputs="text", title="Hybrid AI: InceptionResNetV2 + AdaBoost", description="Upload an image to detect if it's Real/Cat or Fake/Dog." ) if __name__ == "__main__": interface.launch()