File size: 869 Bytes
40fb94f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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}")