callmeuser34 commited on
Commit
a18e6cf
·
verified ·
1 Parent(s): 70391d4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import __main__
4
+
5
+ # 1. THE CRITICAL FIX:
6
+ def label_func(x): return x.parent.name
7
+ __main__.label_func = label_func
8
+
9
+ # 2. LOAD THE LEARNER:
10
+ learn = load_learner('waste_model_448_final_v3.pkl')
11
+ categories = learn.dls.vocab
12
+
13
+ # 3. PREDICTION LOGIC:
14
+ def predict(img):
15
+ img = PILImage.create(img)
16
+ pred, pred_idx, probs = learn.predict(img)
17
+
18
+ # Return a dictionary of {Category: Probability} for the Gradio UI
19
+ return {categories[i]: float(probs[i]) for i in range(len(categories))}
20
+
21
+ # 4. GRADIO INTERFACE DESIGN:
22
+ demo = gr.Interface(
23
+ fn=predict,
24
+ inputs=gr.Image(type="pil"),
25
+ outputs=gr.Label(num_top_classes=3),
26
+ title="♻️ ConvNeXt-50 Waste Classifier",
27
+ description="This AI model identifies waste categories with **98.65% accuracy**. Upload a clear image to begin.",
28
+ article="Developed as part of a Mini Project focusing on high-resolution (448px) deep learning for environmental sustainability."
29
+ )
30
+
31
+ # 5. EXECUTION:
32
+ if __name__ == "__main__":
33
+ demo.launch()