Skip to content
Back

Python-ML Runtime Function Keeps "processing"

  • 0
  • Self Hosted
  • Functions
SuperCode Gnertic
16 Apr, 2025, 22:55

I have a function that is triggered when an image is uploaded, and it removes the background from the image. The function works well locally, but when I deploy it to Appwrite, it remains stuck in a “processing” state. As a result, I’m unable to delete the execution since it’s still marked as running.

Additional context: The function is using the python-ml runtime, and I’m using the rembg library. I’ve also tried using the rembg[cpu] version, but the issue persists. Any guidance or assistance would be greatly appreciated.

The snippet is below

TypeScript
from appwrite.client import Client
from appwrite.services.storage import Storage
from appwrite.input_file import InputFile
from rembg import remove
from PIL import Image

ENDPOINT = 'http://host.docker.internal/v1'
# This Appwrite function will be executed every time your function is triggered
def main(context):
    # You can use the Appwrite SDK to interact with other services
    # For this example, we're using the Users service
    client = (
        Client()
        .set_endpoint(ENDPOINT)
        .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])
        .set_key(context.req.headers["x-appwrite-key"])
    )
    storage = Storage(client)
    file_payload = context.req.body
    actual_file = storage.get_file_download(
        bucket_id=file_payload["bucketId"],
        file_id=file_payload["$id"],   
    )
    context.log(f"File payload: {file_payload}")

    # # Open the image
    context.log(f"Actual file: {actual_file}")
    image = Image.open(actual_file)

    # # Remove background
    output = remove(image)
    storage.delete_file(
        bucket_id=file_payload["bucketId"],
        file_id=file_payload["$id"],
    )

    storage.create_file(
        bucket_id=file_payload["bucketId"],
        file_id=file_payload["$id"],
        file=InputFile.from_bytes(output),
        permissions=file_payload["$permissions"],
    )
    context.log("BG Removed")

    return context.res.empty()
TL;DR
Python-ML runtime function on Appwrite stays stuck in "processing" after uploading an image. Using the rembg library to remove background. Attempted using rembg[cpu] version but issue persists. Solution: Verify the Appwrite SDK setup and confirm the connection with services. Check for potential errors in the function execution logic.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more