Search code examples
androidchaquopy

Transformers in Android Studio Chaquopy


chaquopy {
    productFlavors {
        getByName("py310") { version = "3.10" }
        getByName("py311") { version = "3.11" }
    }

    defaultConfig {
        pip {
            // Install only the pipeline module from transformers with version 4.12.0
            install("numpy")
            install("transformers")
        }
    }
}

Is this possible to install transformers?? The script I have inside python folder looks like this:

from transformers import pipeline
from PIL import Image
import matplotlib.pyplot as plt

def classify_image(image_file):

    # Load model via pipeline
    pipe = pipeline("image-classification", model="sergiocannata/prove_melanomaprova_melanoma")

    # Load model directly
    from transformers import AutoImageProcessor, AutoModelForImageClassification

    processor = AutoImageProcessor.from_pretrained("sergiocannata/prove_melanomaprova_melanoma")
    model = AutoModelForImageClassification.from_pretrained("sergiocannata/prove_melanomaprova_melanoma")

...

I am trying to use a model from transformers inside an app.

Failed to install tokenizers<0.20,>=0.19 from https://files.pythonhosted.org/packages/48/04/2071c150f374aab6d5e92aaec38d0f3c368d227dd9e0469a1f0966ac68d1/tokenizers-0.19.1.tar.gz#sha256=ee59e6680ed0fdbe6b724cf38bd70400a0c1dd623b07ac729087270caeac88e3 (from transformers).


Solution

  • Chaquopy's current options for transformers are listed on its issue tracker:

    • tokenizers 0.10.3 (compatible with transformers==4.15.0)
    • tokenizers 0.7.0 (compatible with transformers==2.11.0)

    Both of these are currently only available for Python 3.8. To change the Python version of your app, see here.