| import tensorflow as tf |
| import keras |
| |
| |
| 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 |
| from tensorflow.keras.models import load_model |
| import joblib |
|
|
| |
| model_path = hf_hub_download( |
| repo_id="abdelac/FakeImageModelKeras", |
| filename="feature_extractor.h5" |
| ) |
|
|
| feature_extractor = load_model(model_path,safe_mode=False) |
| |
| print("Model loaded successfully!") |
|
|
| |
| |
| classifier = joblib.load("adaboost_model.pkl") |
| label_encoder = joblib.load("label_encoder.pkl") |
|
|
| S = 299 |
|
|
| def predict(input_img): |
| |
| img = cv2.resize(input_img, (S, S)) |
| img = img.astype("float32") / 255.0 |
| img = np.expand_dims(img, axis=0) |
| |
| |
| features = feature_extractor.predict(img) |
| features = features.reshape(1, -1) |
| |
| |
| prediction_idx = classifier.predict(features)[0] |
| |
| |
| if prediction_idx == 0: |
| return "Fake or Dog" |
| else: |
| return "Real or Cat" |
|
|
| |
| 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() |