Update app.py
Browse files
app.py
CHANGED
@@ -54,24 +54,30 @@ def predict(image):
|
|
54 |
# Make prediction
|
55 |
output = model(image_tensor)
|
56 |
prediction = output.argmax().item()
|
|
|
57 |
|
|
|
|
|
|
|
|
|
58 |
# Class mapping
|
59 |
class_labels = {0: 'cocci', 1: 'bacilli', 2: 'spirilla'}
|
60 |
|
61 |
# Return prediction result
|
62 |
-
return class_labels[prediction],
|
63 |
except Exception as e:
|
64 |
return {'error': str(e)}
|
65 |
|
|
|
66 |
# Create the Gradio interface
|
67 |
iface = gr.Interface(
|
68 |
fn=predict,
|
69 |
inputs=gr.Image(type="pil", label="Upload an image"),
|
70 |
outputs=[gr.Label(num_top_classes=3, label="Predicted Class"), gr.Number(label="Confidence")],
|
71 |
examples=[
|
72 |
-
"https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/
|
73 |
-
"https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/
|
74 |
-
"https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/
|
75 |
]
|
76 |
)
|
77 |
|
|
|
54 |
# Make prediction
|
55 |
output = model(image_tensor)
|
56 |
prediction = output.argmax().item()
|
57 |
+
confidence = output.max().item()
|
58 |
|
59 |
+
# Print debugging information
|
60 |
+
print(f"Predicted: {prediction}, Confidence: {confidence}")
|
61 |
+
print(f"Model Output: {output}")
|
62 |
+
|
63 |
# Class mapping
|
64 |
class_labels = {0: 'cocci', 1: 'bacilli', 2: 'spirilla'}
|
65 |
|
66 |
# Return prediction result
|
67 |
+
return class_labels[prediction], confidence
|
68 |
except Exception as e:
|
69 |
return {'error': str(e)}
|
70 |
|
71 |
+
|
72 |
# Create the Gradio interface
|
73 |
iface = gr.Interface(
|
74 |
fn=predict,
|
75 |
inputs=gr.Image(type="pil", label="Upload an image"),
|
76 |
outputs=[gr.Label(num_top_classes=3, label="Predicted Class"), gr.Number(label="Confidence")],
|
77 |
examples=[
|
78 |
+
"https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/resolve/main/img%20290.jpg",
|
79 |
+
"https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/resolve/main/img%20565.jpg",
|
80 |
+
"https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/resolve/main/img%208.jpg"
|
81 |
]
|
82 |
)
|
83 |
|