Ultrajonic commited on
Commit
68a3eec
·
1 Parent(s): bc0bc66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -1,12 +1,22 @@
1
- from fastai.vision.all import load_learner
2
- learn = load_learner('CameraTrap_model.pkl')
 
 
3
 
4
- labels = learn.dls.vocab
5
- def predict(img):
6
- img = PILImage.create(img)
7
- pred,pred_idx,probs = learn.predict(img)
8
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
9
 
 
 
 
10
 
11
- import gradio as gr
12
- gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=2)).launch(share=False)
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ from fastai.vision.all import *
4
+ import gradio as gr
5
 
6
+ model_path = '/content/CameraTrap_model.pkl'
7
+ learn = load_learner(model_path)
 
 
 
8
 
9
+ def predict_class(file_path):
10
+ pred, pred_idx, probs = learn.predict(file_path)
11
+ return str(pred)
12
 
13
+ def classify_image(file):
14
+ # Move the file to the respective folders
15
+ if str(file) == 'With_Animals':
16
+ shutil.move(file, os.path.join(animal_folder, file))
17
+ elif str(file) == 'No_Animals':
18
+ shutil.move(file, os.path.join(no_animal_folder, file))
19
+ return 'File classified successfully!'
20
+
21
+ iface = gr.Interface(fn=classify_image, inputs='file', outputs='text', title='Image Classifier')
22
+ iface.launch()