Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,18 +11,21 @@ model = load_model(model_path)
|
|
11 |
|
12 |
# Inference function
|
13 |
def predict(image):
|
14 |
-
|
15 |
-
image =
|
16 |
-
image =
|
17 |
-
image = image
|
18 |
-
|
|
|
|
|
|
|
19 |
prob = model.predict(image)[0][0]
|
20 |
|
21 |
-
#
|
22 |
-
label = "
|
23 |
-
confidence = round(float(prob if
|
24 |
|
25 |
-
return f"{label} ({confidence})"
|
26 |
|
27 |
# Gradio interface
|
28 |
iface = gr.Interface(
|
|
|
11 |
|
12 |
# Inference function
|
13 |
def predict(image):
|
14 |
+
# === Short-Term Workaround for Inference ===
|
15 |
+
image = image.convert("RGB") # Ensure 3 color channels
|
16 |
+
image = image.resize((299, 299)) # Resize to match model input
|
17 |
+
image = img_to_array(image).astype("float32") # Convert to array + ensure float32
|
18 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
19 |
+
image /= 255.0 # Normalize to [0, 1] like during training
|
20 |
+
|
21 |
+
# Model prediction
|
22 |
prob = model.predict(image)[0][0]
|
23 |
|
24 |
+
# 0 = Fake, 1 = Real
|
25 |
+
label = "Fake" if prob < 0.5 else "Real"
|
26 |
+
confidence = round(float(1 - prob if label == "Fake" else prob), 3)
|
27 |
|
28 |
+
return f"{label} ({confidence * 100:.1f}%)"
|
29 |
|
30 |
# Gradio interface
|
31 |
iface = gr.Interface(
|