Spaces:
Build error
Build error
Commit ·
29fbe38
1
Parent(s): 76684f9
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,11 +11,20 @@ def predict_class(file_path):
|
|
| 11 |
return str(pred)
|
| 12 |
|
| 13 |
def classify_image(file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Move the file to the respective folders
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
return 'File classified successfully!'
|
| 20 |
|
| 21 |
iface = gr.Interface(fn=classify_image, inputs='file', outputs='text', title='Image Classifier From CameraTrap')
|
|
|
|
| 11 |
return str(pred)
|
| 12 |
|
| 13 |
def classify_image(file):
|
| 14 |
+
# Create your own destination folders
|
| 15 |
+
animal_folder = 'path/to/animal_folder'
|
| 16 |
+
no_animal_folder = 'path/to/no_animal_folder'
|
| 17 |
+
|
| 18 |
+
os.makedirs(animal_folder, exist_ok=True)
|
| 19 |
+
os.makedirs(no_animal_folder, exist_ok=True)
|
| 20 |
+
|
| 21 |
# Move the file to the respective folders
|
| 22 |
+
pred_class = predict_class(file.name)
|
| 23 |
+
if pred_class == 'With_Animals':
|
| 24 |
+
shutil.move(file.name, os.path.join(animal_folder, file.name))
|
| 25 |
+
elif pred_class == 'No_Animals':
|
| 26 |
+
shutil.move(file.name, os.path.join(no_animal_folder, file.name))
|
| 27 |
+
|
| 28 |
return 'File classified successfully!'
|
| 29 |
|
| 30 |
iface = gr.Interface(fn=classify_image, inputs='file', outputs='text', title='Image Classifier From CameraTrap')
|