Download scripts/analyze_image.py from Fred808/Insta-AI: direct link, hf CLI and curl.
- Browser
- Download file 869 Bytes
-
https://huggingface.co/spaces/Fred808/Insta-AI/resolve/main/scripts/analyze_image.py
- Command line
-
hf download hf://spaces/Fred808/Insta-AI/scripts/analyze_image.py
-
curl -L -o analyze_image.py https://huggingface.co/spaces/Fred808/Insta-AI/resolve/main/scripts/analyze_image.py
869 Bytes
| import requests | |
| from PIL import Image | |
| from io import BytesIO | |
| from utils.image_processing import extract_text_from_image, analyze_image | |
| from utils.logging_utils import setup_logging | |
| def analyze_image_url(image_url, caption): | |
| """Analyze an image from a URL.""" | |
| setup_logging() | |
| try: | |
| # Download the image | |
| response = requests.get(image_url) | |
| response.raise_for_status() | |
| image = Image.open(BytesIO(response.content)) | |
| # Extract text from the image | |
| extracted_text = extract_text_from_image(image) | |
| logging.info(f"Extracted text: {extracted_text}") | |
| # Analyze the image | |
| image_analysis = analyze_image(image) | |
| if image_analysis is not None: | |
| logging.info("Image analysis completed successfully.") | |
| except Exception as e: | |
| logging.error(f"Error processing image: {e}") |