valiyevfagan commited on
Commit
c803f21
·
verified ·
1 Parent(s): 9af68af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,7 +1,25 @@
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
4
+ # Load the exported model
5
+ learn = load_learner('trash_model(1s).pkl')
6
 
7
+ # Define labels (make sure they match your model's training labels)
8
+ labels = learn.dls.vocab
9
+
10
+ # Define prediction function
11
+ def classify_trash(img):
12
+ pred_class, pred_idx, probs = learn.predict(img)
13
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
14
+
15
+ # Gradio Interface
16
+ interface = gr.Interface(
17
+ fn=classify_trash,
18
+ inputs=gr.Image(type="pil"),
19
+ outputs=gr.Label(num_top_classes=5),
20
+ title="Trash Classifier",
21
+ description="Upload a trash image to classify it into one of 5 categories."
22
+ )
23
+
24
+ # Launch app
25
+ interface.launch()