LogicGoInfotechSpaces's picture
Add project files
0ed44c0
metadata
title: Nano Banana Image Edit API
emoji: 🍌
colorFrom: pink
colorTo: indigo
sdk: docker
pinned: false
short_description: NanoBanana and Descratch Model

Nano Banana Image Edit API

A FastAPI-based REST API for the Qwen Image Edit model that allows you to upload images, edit them with text prompts, and retrieve results.

Features

  • Upload Images: Upload image files via POST request
  • Edit Images: Submit image ID and text prompt to edit images
  • Get Results: Retrieve edited images by task ID
  • Multiple Formats: Get results as files or base64-encoded strings

API Endpoints

1. Upload Image

POST /upload

Upload an image file.

Request:

  • Content-Type: multipart/form-data
  • Body: file (image file)

Response:

{
  "image_id": "uuid-string",
  "message": "Image uploaded successfully",
  "timestamp": "2024-01-01T12:00:00"
}

2. Edit Image

POST /edit

Edit an uploaded image using a text prompt.

Request:

  • Content-Type: multipart/form-data
  • Body:
    • image_id: ID of uploaded image
    • prompt: Text description of desired edit

Response:

{
  "task_id": "uuid-string",
  "status": "completed",
  "message": "Image edited successfully",
  "timestamp": "2024-01-01T12:00:00"
}

3. Get Result

GET /result/{task_id}

Get the status and result information for an editing task.

4. Get Result Image (File)

GET /result/image/{result_image_id}

Download the edited image as a file.

5. Get Result Image (Base64)

GET /result/image/{result_image_id}/base64

Get the edited image as a base64-encoded string.

6. Health Check

GET /health

Check API health and model status.

Interactive API Documentation

Once the Space is running, visit:

  • Swagger UI: /docs
  • ReDoc: /redoc

Usage Example (Python)

import requests

# Upload image
with open("image.jpg", "rb") as f:
    response = requests.post(
        "https://your-space-url/upload",
        files={"file": f}
    )
upload_data = response.json()
image_id = upload_data["image_id"]

# Edit image
response = requests.post(
    "https://your-space-url/edit",
    data={
        "image_id": image_id,
        "prompt": "make the background sunset orange"
    }
)
edit_data = response.json()
task_id = edit_data["task_id"]

# Get result
response = requests.get(f"https://your-space-url/result/{task_id}")
result_data = response.json()
result_image_id = result_data["result_image_id"]

# Download edited image
response = requests.get(f"https://your-space-url/result/image/{result_image_id}")
with open("edited_image.png", "wb") as f:
    f.write(response.content)

Model

This API uses the Qwen/Qwen-Image-Edit model from Hugging Face, which is open source under Apache 2.0 license.

Notes

  • The current implementation uses in-memory storage for tasks. For production, consider using:
    • Redis or database for task storage
    • S3, Azure Blob Storage, or similar for image storage
    • Proper authentication and rate limiting
    • Async task processing with Celery or similar