Zeyadd-Mostaffa commited on
Commit
fb886c0
·
verified ·
1 Parent(s): a3131e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -11,18 +11,21 @@ model = load_model(model_path)
11
 
12
  # Inference function
13
  def predict(image):
14
- image = image.resize((299, 299))
15
- image = img_to_array(image)
16
- image = np.expand_dims(image, axis=0)
17
- image = image / 255.0 # normalize to match training
18
-
 
 
 
19
  prob = model.predict(image)[0][0]
20
 
21
- # Based on your notebook: label 0 = Fake, label 1 = Real
22
- label = "Real" if prob > 0.5 else "Fake"
23
- confidence = round(float(prob if prob > 0.5 else 1 - prob), 3)
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(