ragipindivaishnavi commited on
Commit
539c5a4
·
verified ·
1 Parent(s): 3bb74fb

Upload 3 files

Browse files
Files changed (3) hide show
  1. ExtraTreesClassifier.pkl +3 -0
  2. app.py +54 -0
  3. requirements.txt +6 -0
ExtraTreesClassifier.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1ac22d924a196ada8f75ca42320f71b46828e9fbfdbdff7e989577d19d75551
3
+ size 4211049
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import cv2
4
+ import joblib
5
+ import os
6
+
7
+ # ================= LOAD MODEL =================
8
+ MODEL_PATH = "ExtraTreesClassifier.pkl"
9
+
10
+ if not os.path.exists(MODEL_PATH):
11
+ raise FileNotFoundError("Model not found! Train and save Model first.")
12
+
13
+ model = joblib.load(MODEL_PATH)
14
+
15
+ # ================= CATEGORY LABELS =================
16
+ # ⚠️ IMPORTANT: Replace with your actual folder names in SAME ORDER
17
+ categories = ["Defective", "Normal"]
18
+
19
+
20
+ # ================= PREDICTION FUNCTION =================
21
+ def predict_image(image):
22
+ try:
23
+ # Convert to numpy
24
+ img = np.array(image)
25
+
26
+ # Resize
27
+ img = cv2.resize(img, (64, 64))
28
+
29
+ # Normalize
30
+ img = img / 255.0
31
+
32
+ # Flatten
33
+ img = img.flatten().reshape(1, -1)
34
+
35
+ # Predict
36
+ pred = model.predict(img)[0]
37
+ label = categories[pred]
38
+
39
+ return f"Predicted Class: {label}"
40
+
41
+ except Exception as e:
42
+ return f"Error: {str(e)}"
43
+
44
+
45
+ # ================= GRADIO UI =================
46
+ interface = gr.Interface(
47
+ fn=predict_image,
48
+ inputs=gr.Image(type="pil"),
49
+ outputs="text",
50
+ title="Cating Product Defect Classification From Images",
51
+ description="Upload an image to predict its category"
52
+ )
53
+
54
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ opencv-python
4
+ joblib
5
+ scikit-learn
6
+ pillow