Update app.py
Browse files
app.py
CHANGED
@@ -76,18 +76,22 @@ def predict_image(img, confidence_threshold):
|
|
76 |
# Check if either class meets the confidence threshold
|
77 |
if result_1['artificial'] >= confidence_threshold:
|
78 |
label_1 = f"AI, Confidence: {result_1['artificial']:.4f}"
|
|
|
79 |
elif result_1['real'] >= confidence_threshold:
|
80 |
label_1 = f"Real, Confidence: {result_1['real']:.4f}"
|
|
|
81 |
else:
|
82 |
label_1 = "Uncertain Classification"
|
|
|
|
|
83 |
except Exception as e:
|
84 |
label_1 = f"Error: {str(e)}"
|
85 |
-
|
86 |
# Predict using the second model
|
87 |
try:
|
88 |
prediction_2 = clf_2(img_pil)
|
89 |
result_2 = {pred['label']: pred['score'] for pred in prediction_2}
|
90 |
-
result_2output = [2, result_2['
|
91 |
print(result_2output)
|
92 |
# Ensure the result dictionary contains all class names
|
93 |
for class_name in class_names_2:
|
|
|
76 |
# Check if either class meets the confidence threshold
|
77 |
if result_1['artificial'] >= confidence_threshold:
|
78 |
label_1 = f"AI, Confidence: {result_1['artificial']:.4f}"
|
79 |
+
result_1output += ['AI']
|
80 |
elif result_1['real'] >= confidence_threshold:
|
81 |
label_1 = f"Real, Confidence: {result_1['real']:.4f}"
|
82 |
+
result_1output += ['REAL']
|
83 |
else:
|
84 |
label_1 = "Uncertain Classification"
|
85 |
+
result_1output += ['UNCERTAIN']
|
86 |
+
|
87 |
except Exception as e:
|
88 |
label_1 = f"Error: {str(e)}"
|
89 |
+
print(result_1output)
|
90 |
# Predict using the second model
|
91 |
try:
|
92 |
prediction_2 = clf_2(img_pil)
|
93 |
result_2 = {pred['label']: pred['score'] for pred in prediction_2}
|
94 |
+
result_2output = [2, result_2['Real Image'], result_2['AI Image']]
|
95 |
print(result_2output)
|
96 |
# Ensure the result dictionary contains all class names
|
97 |
for class_name in class_names_2:
|