Insta-AI / scripts /analyze_image.py
Sam Fred
Commit
40fb94f
raw
history blame contribute delete
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}")