CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-modal

Python client library for Modal, a serverless cloud computing platform that enables developers to run Python code in the cloud with on-demand access to compute resources.

85

1.60x
Overview
Eval results
Files

task.mdevals/scenario-4/

Image Classification Service

Build a serverless image classification service that efficiently processes multiple image classification requests using batch processing.

Background

You're building an image classification API that receives many individual image classification requests from clients. Each client sends a single image URL and expects a classification result. However, the underlying model performs better when processing multiple images at once.

Requirements

Batch Processing

The service should automatically batch individual classification requests together for efficient processing, even though clients send requests one at a time.

API Endpoint

Create a web endpoint that:

  • Accepts POST requests with a JSON body containing an image_url field
  • Returns a JSON response with a class field containing the predicted class name
  • Handles multiple concurrent requests efficiently

Classification Logic

Implement a classification function that:

  • Processes multiple images in a single batch operation
  • Returns mock classification results (you can use simple logic like selecting a class based on URL length or hash)
  • Includes a simulated processing delay to represent model inference time

Test Cases

  • A single request to the endpoint returns a valid classification response with a class field @test
  • Multiple concurrent requests (5 requests sent simultaneously) all complete successfully and return valid responses @test
  • The endpoint accepts image URLs and returns different class predictions for different URLs @test

Implementation

@generates

API

# Modal app that exposes a web endpoint for image classification
# POST endpoint accepts: {"image_url": "https://example.com/image.jpg"}
# Returns: {"class": "cat"}

Dependencies { .dependencies }

modal { .dependency }

Provides serverless cloud compute capabilities for running the classification service.

Install with Tessl CLI

npx tessl i tessl/pypi-modal

tile.json