Spaces:
Runtime error
Runtime error
NORLIE JHON MALAGDAO
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
batch_size = 32
|
2 |
img_height = 180
|
3 |
img_width = 180
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
import PIL
|
6 |
+
import tensorflow as tf
|
7 |
+
|
8 |
+
from tensorflow import keras
|
9 |
+
from tensorflow.keras import layers
|
10 |
+
from tensorflow.keras.models import Sequential
|
11 |
+
|
12 |
+
|
13 |
+
from PIL import Image
|
14 |
+
import gdown
|
15 |
+
import zipfile
|
16 |
+
|
17 |
+
import pathlib
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
# Define the Google Drive shareable link
|
24 |
+
gdrive_url = 'https://drive.google.com/file/d/1HjHYlQyRz5oWt8kehkt1TiOGRRlKFsv8/view?usp=drive_link'
|
25 |
+
|
26 |
+
# Extract the file ID from the URL
|
27 |
+
file_id = gdrive_url.split('/d/')[1].split('/view')[0]
|
28 |
+
direct_download_url = f'https://drive.google.com/uc?id={file_id}'
|
29 |
+
|
30 |
+
# Define the local filename to save the ZIP file
|
31 |
+
local_zip_file = 'file.zip'
|
32 |
+
|
33 |
+
# Download the ZIP file
|
34 |
+
gdown.download(direct_download_url, local_zip_file, quiet=False)
|
35 |
+
|
36 |
+
# Directory to extract files
|
37 |
+
extracted_path = 'extracted_files'
|
38 |
+
|
39 |
+
# Verify if the downloaded file is a ZIP file and extract it
|
40 |
+
try:
|
41 |
+
with zipfile.ZipFile(local_zip_file, 'r') as zip_ref:
|
42 |
+
zip_ref.extractall(extracted_path)
|
43 |
+
print("Extraction successful!")
|
44 |
+
except zipfile.BadZipFile:
|
45 |
+
print("Error: The downloaded file is not a valid ZIP file.")
|
46 |
+
|
47 |
+
# Optionally, you can delete the ZIP file after extraction
|
48 |
+
os.remove(local_zip_file)
|
49 |
+
|
50 |
+
# Convert the extracted directory path to a pathlib.Path object
|
51 |
+
data_dir = pathlib.Path(extracted_path)
|
52 |
+
|
53 |
+
# Print the directory structure to debug
|
54 |
+
for root, dirs, files in os.walk(extracted_path):
|
55 |
+
level = root.replace(extracted_path, '').count(os.sep)
|
56 |
+
indent = ' ' * 4 * (level)
|
57 |
+
print(f"{indent}{os.path.basename(root)}/")
|
58 |
+
subindent = ' ' * 4 * (level + 1)
|
59 |
+
for f in files:
|
60 |
+
print(f"{subindent}{f}")
|
61 |
+
|
62 |
+
import pathlib
|
63 |
+
# Path to the dataset directory
|
64 |
+
data_dir = pathlib.Path('extracted_files/Pest_Dataset')
|
65 |
+
data_dir = pathlib.Path(data_dir)
|
66 |
+
|
67 |
+
|
68 |
+
bees = list(data_dir.glob('bees/*'))
|
69 |
+
print(bees[0])
|
70 |
+
PIL.Image.open(str(bees[0]))
|
71 |
+
|
72 |
+
|
73 |
+
bees = list(data_dir.glob('bees/*'))
|
74 |
+
print(bees[0])
|
75 |
+
PIL.Image.open(str(bees[0]))
|
76 |
+
|
77 |
batch_size = 32
|
78 |
img_height = 180
|
79 |
img_width = 180
|