File size: 747 Bytes
43b0175
 
 
 
4419595
43b0175
a65b579
43b0175
 
a65b579
43b0175
 
 
2ec297b
 
43b0175
a65b579
43b0175
 
 
 
 
2ec297b
 
43b0175
 
a65b579
43b0175
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from fastai.vision.all import *
import gradio as gr

# Load the exported model
learn = load_learner('trash_model(1).pkl')

# Define labels (make sure they match your model's training labels)
labels = learn.dls.vocab

# Define prediction function
def classify_trash(img):
    pred_class, pred_idx, probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}
    
examples = ["glass.png","plastic.jpg"]

# Gradio Interface
interface = gr.Interface(
    fn=classify_trash,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=5),
    title="Trash Classifier",
    description="Upload a trash image to classify it into one of 5 categories.",
    examples=examples
)

# Launch app
interface.launch()