File size: 1,058 Bytes
68a3eec
 
 
 
b9e50cc
1c8c513
68a3eec
b9e50cc
68a3eec
 
 
b9e50cc
68a3eec
29fbe38
62019f9
 
29fbe38
 
 
 
68a3eec
29fbe38
 
 
 
 
 
68a3eec
 
76684f9
68a3eec
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
30
31
import os
import shutil
from fastai.vision.all import *
import gradio as gr

model_path = 'CameraTrapModel.pkl'
learn = load_learner(model_path)

def predict_class(file_path):
    pred, pred_idx, probs = learn.predict(file_path)
    return str(pred)

def classify_image(file):
    # Create your own destination folders
    animal_folder = '/content/gdrive/MyDrive/My_DataSets/With_animal(s)_Rslts'
    no_animal_folder = '/content/gdrive/MyDrive/My_DataSets/No_animal(s)_Rslts'

    os.makedirs(animal_folder, exist_ok=True)
    os.makedirs(no_animal_folder, exist_ok=True)

    # Move the file to the respective folders
    pred_class = predict_class(file.name)
    if pred_class == 'With_Animals':
        shutil.move(file.name, os.path.join(animal_folder, file.name))
    elif pred_class == 'No_Animals':
        shutil.move(file.name, os.path.join(no_animal_folder, file.name))
    
    return 'File classified successfully!'

iface = gr.Interface(fn=classify_image, inputs='file', outputs='text', title='Image Classifier From CameraTrap')
iface.launch()