benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 5b6937d6-ff59-58bb-90c8-3f9880e8a323

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import requests
from PIL import Image
import io


def task_func(url):
    """
    Fetches an image from a given URL and returns it as a PIL Image object.

    Parameters:
    - url (str): The URL of the image to download. It should be a valid HTTP or
      HTTPS URL pointing directly to an image file.

    Returns:
    - PIL.Image.Image: A PIL Image object representing the downloaded image. This
      object can be manipulated or displayed using PIL's image processing
      capabilities.

    Raises:
    - ValueError: This exception is raised in the following scenarios:
        - The URL is invalid or cannot be reached within the timeout period (5 seconds).
        - The response from the server is not a successful HTTP status code (i.e., not in the range 200-299).
        - The content fetched from the URL is not a valid image format that can be handled by PIL.

    Requirements:
    - requests
    - PIL
    - io

    Example:
    >>> img = task_func('https://example.com/image.jpg')
    >>> isinstance(img, Image.Image)
    True

    Note:
    - The function uses a timeout of 5 seconds for the HTTP request to prevent
      indefinite waiting in case of unresponsive URLs.
    - The function will not handle redirections or authentication scenarios. It
      expects a direct link to an image resource.
    """

instruct prompt

Fetches an image from a given URL and returns it as a PIL Image object.
Note that: The function uses a timeout of 5 seconds for the HTTP request to prevent indefinite waiting in case of unresponsive URLs. The function will not handle redirections or authentication scenarios. It expects a direct link to an image resource.
The function should raise the exception for: ValueError: This exception is raised in the following scenarios: The URL is invalid or cannot be reached within the timeout period (5 seconds). The response from the server is not a successful HTTP status code (i.e., not in the range 200-299). The content fetched from the URL is not a valid image format that can be handled by PIL.
The function should output with:
    PIL.Image.Image: A PIL Image object representing the downloaded image. This
    object can be manipulated or displayed using PIL's image processing
    capabilities.
You should write self-contained code starting with:

Code

import requests
from PIL import Image
import io
def task_func(url):

code prompt

Code

import requests
from PIL import Image
import io
def task_func(url):

entry point

task_func

libs

  • io
  • PIL
  • requests

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import