File size: 1,677 Bytes
824cd11
 
 
 
 
 
 
 
 
 
 
 
aafeb7e
 
a943095
aafeb7e
cd055a5
 
aafeb7e
4351477
aafeb7e
 
0aa3dbd
cdc131a
a943095
aafeb7e
 
824cd11
aafeb7e
824cd11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()