Update app.py
Browse files
app.py
CHANGED
@@ -17,8 +17,17 @@ clf = pipeline(model=model, task="image-classification", image_processor=image_p
|
|
17 |
class_names = ['artificial', 'real']
|
18 |
|
19 |
def predict_image(img, confidence_threshold):
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
img_pil = transforms.Resize((256, 256))(img_pil)
|
23 |
|
24 |
# Get the prediction
|
@@ -39,7 +48,7 @@ def predict_image(img, confidence_threshold):
|
|
39 |
return f"Label: real, Confidence: {result['real']:.4f}"
|
40 |
else:
|
41 |
return "Uncertain Classification"
|
42 |
-
|
43 |
# Define the Gradio interface
|
44 |
image = gr.Image(label="Image to Analyze", sources=['upload'], type='pil') # Ensure the image type is PIL
|
45 |
confidence_slider = gr.Slider(0.0, 1.0, value=0.5, step=0.01, label="Confidence Threshold")
|
|
|
17 |
class_names = ['artificial', 'real']
|
18 |
|
19 |
def predict_image(img, confidence_threshold):
|
20 |
+
print(f"Type of img: {type(img)}") # Debugging statement
|
21 |
+
if not isinstance(img, Image.Image):
|
22 |
+
raise ValueError(f"Expected a PIL Image, but got {type(img)}")
|
23 |
+
|
24 |
+
# Convert the image to RGB if not already
|
25 |
+
if img.mode != 'RGB':
|
26 |
+
img_pil = img.convert('RGB')
|
27 |
+
else:
|
28 |
+
img_pil = img
|
29 |
+
|
30 |
+
# Resize the image
|
31 |
img_pil = transforms.Resize((256, 256))(img_pil)
|
32 |
|
33 |
# Get the prediction
|
|
|
48 |
return f"Label: real, Confidence: {result['real']:.4f}"
|
49 |
else:
|
50 |
return "Uncertain Classification"
|
51 |
+
|
52 |
# Define the Gradio interface
|
53 |
image = gr.Image(label="Image to Analyze", sources=['upload'], type='pil') # Ensure the image type is PIL
|
54 |
confidence_slider = gr.Slider(0.0, 1.0, value=0.5, step=0.01, label="Confidence Threshold")
|