Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,15 +34,27 @@ def search_images_for_presentation(query: str) -> str:
|
|
| 34 |
@tool
|
| 35 |
def save_image_from_browser(image_url: str) -> str:
|
| 36 |
"""
|
| 37 |
-
|
| 38 |
Args:
|
| 39 |
image_url: The URL of the image to be saved.
|
| 40 |
Returns:
|
| 41 |
str: The path to the saved image.
|
| 42 |
"""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
# Initialize agent (same as before)
|
|
|
|
| 34 |
@tool
|
| 35 |
def save_image_from_browser(image_url: str) -> str:
|
| 36 |
"""
|
| 37 |
+
Downloads and saves the image from the given URL.
|
| 38 |
Args:
|
| 39 |
image_url: The URL of the image to be saved.
|
| 40 |
Returns:
|
| 41 |
str: The path to the saved image.
|
| 42 |
"""
|
| 43 |
+
# Download image from the URL
|
| 44 |
+
try:
|
| 45 |
+
response = requests.get(image_url)
|
| 46 |
+
response.raise_for_status()
|
| 47 |
+
|
| 48 |
+
# Save the image locally (you can adjust the save path as needed)
|
| 49 |
+
image_path = f"/path/to/save/directory/{image_url.split('/')[-1]}"
|
| 50 |
+
with open(image_path, "wb") as file:
|
| 51 |
+
file.write(response.content)
|
| 52 |
+
|
| 53 |
+
return image_path
|
| 54 |
+
except requests.exceptions.RequestException as e:
|
| 55 |
+
print(f"Error downloading image: {e}")
|
| 56 |
+
return None
|
| 57 |
+
|
| 58 |
|
| 59 |
|
| 60 |
# Initialize agent (same as before)
|