Spaces:
Sleeping
Sleeping
Add application to deploy
Browse files- .gitignore +1 -0
- app.py +39 -0
- requirements.txt +2 -0
- resnet_model_17_Sep_1.pkl +3 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
*.idea
|
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import pathlib
|
4 |
+
plt = platform.system()
|
5 |
+
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
6 |
+
|
7 |
+
current_dir = os.getcwd()
|
8 |
+
model = 'resnet_model_14_Sep_1.pkl'
|
9 |
+
model_path = os.path.join(current_dir, model)
|
10 |
+
|
11 |
+
model = load_learner(model_path)
|
12 |
+
|
13 |
+
|
14 |
+
st.title("Defect Classification")
|
15 |
+
st.write("Upload an image to check whether if it's normal or defective (stain)")
|
16 |
+
|
17 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
18 |
+
|
19 |
+
if uploaded_file is not None:
|
20 |
+
image = Image.open(uploaded_file)
|
21 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
22 |
+
|
23 |
+
# Perform Predictions
|
24 |
+
if st.button("Predict"):
|
25 |
+
img = PILImage.create(uploaded_file)
|
26 |
+
# Make predictions
|
27 |
+
predictions, _ = model.get_preds(dl=model.dls.test_dl([img]))
|
28 |
+
# Get the predicted class index
|
29 |
+
predicted_class_idx = predictions.argmax(dim=1).item()
|
30 |
+
# Get the confidence score for the predicted class
|
31 |
+
confidence_score = predictions[0][predicted_class_idx].item()
|
32 |
+
# Map the class index to class name
|
33 |
+
class_names = model.dls.vocab
|
34 |
+
predicted_class = class_names[predicted_class_idx]
|
35 |
+
|
36 |
+
# Display the prediction and confidence score
|
37 |
+
st.write(f"Prediction: {predicted_class}")
|
38 |
+
st.write(f"Confidence: {confidence_score:.4f}")
|
39 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit==1.26.0
|
2 |
+
fastai==2.7.12
|
resnet_model_17_Sep_1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ba5ac0313e80c5736cede33bc749ce6c0a1f237f9a4d7482360f0cdc19c1db00
|
3 |
+
size 47002013
|