WoodLB commited on
Commit
1e6e6f3
·
1 Parent(s): dd3f39c

finished app no frills

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -95,18 +95,35 @@ def train_and_inference(api_key, ontology_id, model_run_id):
95
  import requests
96
  import os
97
 
98
- def download_and_save_image(url, destination_folder, filename):
 
 
 
 
 
 
 
 
 
99
  if not os.path.exists(destination_folder):
100
  os.makedirs(destination_folder)
101
 
 
102
  response = requests.get(url, stream=True)
103
- response.raise_for_status()
104
- st.write(url)
105
 
106
- with open(os.path.join(destination_folder, filename), 'wb') as file:
107
- for chunk in response.iter_content(8192):
108
- file.write(chunk)
109
- file.close()
 
 
 
 
 
 
 
 
 
110
 
111
  BASE_DIR = 'dataset'
112
 
 
95
  import requests
96
  import os
97
 
98
+ import os
99
+ import requests
100
+ from urllib.parse import unquote
101
+
102
+ def download_and_save_image(url, destination_folder, filename):
103
+ try:
104
+ # Decode the URL
105
+ url = unquote(url)
106
+
107
+ # Ensure destination directory exists
108
  if not os.path.exists(destination_folder):
109
  os.makedirs(destination_folder)
110
 
111
+ # Start the download process
112
  response = requests.get(url, stream=True)
 
 
113
 
114
+ # Check if the request was successful
115
+ if response.status_code == 200:
116
+ file_path = os.path.join(destination_folder, filename)
117
+ with open(file_path, 'wb') as file:
118
+ for chunk in response.iter_content(8192):
119
+ file.write(chunk)
120
+ st.write(f"Image downloaded and saved: {file_path}")
121
+ else:
122
+ st.write(f"Failed to download the image. Status code: {response.status_code}")
123
+ except Exception as e:
124
+ st.write(f"An error occurred: {e}")
125
+
126
+
127
 
128
  BASE_DIR = 'dataset'
129