remove local storage of images
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +9 -10
- fetch_img.py +3 -12
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -230,18 +230,17 @@ def prepare_images(scientific_name: str):
|
|
230 |
print(f"Deleted: {file_path}")
|
231 |
|
232 |
# Save images to assets
|
233 |
-
download_images(f"https://ebird.org/species/{scode}")
|
234 |
-
|
235 |
-
# Return array of
|
236 |
nsplit = scientific_name.split(" ")
|
237 |
abbreviate_name = nsplit[0][0] + "." + " " + nsplit[1]
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
return
|
244 |
-
|
245 |
|
246 |
sp_and_cl = """<div align="center">
|
247 |
<b> <h2> Class and Species Prediction </h2> </b>
|
|
|
230 |
print(f"Deleted: {file_path}")
|
231 |
|
232 |
# Save images to assets
|
233 |
+
urls = download_images(f"https://ebird.org/species/{scode}")
|
234 |
+
|
235 |
+
# Return array of remote image urls labelled
|
236 |
nsplit = scientific_name.split(" ")
|
237 |
abbreviate_name = nsplit[0][0] + "." + " " + nsplit[1]
|
238 |
+
|
239 |
+
# If empty, do not iterate
|
240 |
+
if not urls:
|
241 |
+
return []
|
242 |
+
|
243 |
+
return [(url, abbreviate_name) for url in urls]
|
|
|
244 |
|
245 |
sp_and_cl = """<div align="center">
|
246 |
<b> <h2> Class and Species Prediction </h2> </b>
|
fetch_img.py
CHANGED
@@ -36,10 +36,7 @@ def get_bird_info(species_code : str):
|
|
36 |
data = response.content
|
37 |
return data
|
38 |
|
39 |
-
def download_images(url
|
40 |
-
# Create a folder to save images if it doesn't exist
|
41 |
-
if not os.path.exists(folder_path):
|
42 |
-
os.makedirs(folder_path)
|
43 |
|
44 |
# Fetch the HTML content of the webpage
|
45 |
response = requests.get(url, verify=False)
|
@@ -56,14 +53,8 @@ def download_images(url, folder_path='./assets'):
|
|
56 |
# Extract image URLs
|
57 |
img_urls = [urljoin(url, img['src']) for img in img_tags if 'src' in img.attrs]
|
58 |
img_urls = [el for el in img_urls if "api" in el and "asset" in el]
|
59 |
-
|
60 |
-
|
61 |
-
try:
|
62 |
-
img_path = os.path.join(folder_path, f'image_{i+1}.jpg')
|
63 |
-
urllib.request.urlretrieve(img_url, img_path)
|
64 |
-
print(f"Downloaded: {img_url}")
|
65 |
-
except Exception as e:
|
66 |
-
print(f"Failed to download {img_url}. Error: {e}")
|
67 |
|
68 |
if __name__ == '__main__':
|
69 |
bird_tax = pd.read_csv("ebird_taxonomy_v2023.csv")
|
|
|
36 |
data = response.content
|
37 |
return data
|
38 |
|
39 |
+
def download_images(url):
|
|
|
|
|
|
|
40 |
|
41 |
# Fetch the HTML content of the webpage
|
42 |
response = requests.get(url, verify=False)
|
|
|
53 |
# Extract image URLs
|
54 |
img_urls = [urljoin(url, img['src']) for img in img_tags if 'src' in img.attrs]
|
55 |
img_urls = [el for el in img_urls if "api" in el and "asset" in el]
|
56 |
+
|
57 |
+
return img_urls
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
if __name__ == '__main__':
|
60 |
bird_tax = pd.read_csv("ebird_taxonomy_v2023.csv")
|