Spaces:
Build error
Build error
Commit
·
68a3eec
1
Parent(s):
bc0bc66
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,22 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
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 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|