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