Spaces:
Runtime error
Runtime error
Zell
commited on
Commit
·
604195d
1
Parent(s):
2a5d6bd
Fix prediction error
Browse files
app.py
CHANGED
@@ -27,17 +27,24 @@ def detect_forgery(image):
|
|
27 |
img = img / 255.0 # Example normalization; adapt as needed
|
28 |
|
29 |
# Run inference
|
30 |
-
predictions = model.predict(img)[0]
|
|
|
|
|
31 |
# Suppose predictions = [prob_real, prob_fake]
|
32 |
-
|
33 |
-
prob_fake = predictions[1]
|
34 |
|
35 |
# Format output
|
36 |
# You can return a dictionary or a string. For example:
|
37 |
-
if
|
38 |
-
|
|
|
|
|
39 |
else:
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# 3. Build your Gradio interface
|
43 |
demo = gr.Interface(
|
@@ -50,4 +57,5 @@ demo = gr.Interface(
|
|
50 |
|
51 |
# 4. Launch the app (Gradio handles the rest)
|
52 |
if __name__ == "__main__":
|
|
|
53 |
demo.launch()
|
|
|
27 |
img = img / 255.0 # Example normalization; adapt as needed
|
28 |
|
29 |
# Run inference
|
30 |
+
predictions = model.predict(img)[0]
|
31 |
+
|
32 |
+
pred_value = float(predictions) # or pred_value.item()
|
33 |
# Suppose predictions = [prob_real, prob_fake]
|
34 |
+
|
|
|
35 |
|
36 |
# Format output
|
37 |
# You can return a dictionary or a string. For example:
|
38 |
+
if pred_value >= 0.5:
|
39 |
+
# It's real, use p as the confidence
|
40 |
+
confidence = pred_value
|
41 |
+
label = "REAL"
|
42 |
else:
|
43 |
+
# It's fake, confidence is (1 - p)
|
44 |
+
confidence = 1.0 - pred_value
|
45 |
+
label = "FAKE"
|
46 |
+
|
47 |
+
return f"{label} with confidence {confidence:.2f}"
|
48 |
|
49 |
# 3. Build your Gradio interface
|
50 |
demo = gr.Interface(
|
|
|
57 |
|
58 |
# 4. Launch the app (Gradio handles the rest)
|
59 |
if __name__ == "__main__":
|
60 |
+
_ = model.predict(np.zeros((1, 160, 160, 3), dtype=np.float32))
|
61 |
demo.launch()
|