Skip to content

fxnai/fxn

Repository files navigation

Function for Python and CLI

function logo

Dynamic JSON Badge

Run AI prediction functions (a.k.a "predictors") in your Python apps. With Function, you can build AI-powered apps by creating and composing GPU-accelerated predictors that run in the cloud. In a few steps:

Installing Function

Function is distributed on PyPi. This distribution contains both the Python client and the command line interface (CLI). To install, open a terminal and run the following command:

pip install --upgrade fxn

Note

Function requires Python 3.9+

Making a Prediction

Let's run the @samplefxn/stable-diffusion predictor which accepts a text prompt and generates a corresponding image.

In Python

Run the following Python script:

from fxn import Function

# Create the Function client
fxn = Function()
# Create a prediction
prediction = fxn.predictions.create(
    tag="@samplefxn/stable-diffusion",
    inputs={
        "prompt": "An astronaut riding a horse on Mars"
    }
)
# Show the generated image
image = prediction.results[0]
image.show()

In the CLI

Open up a terminal and run the following command:

fxn predict @samplefxn/stable-diffusion --prompt "An astronaut riding a horse on the moon"

Within a few seconds, you should see a creepy-looking image pop up 😅:

prediction

Creating a Predictor

At some point, you might want to create your own predictor. With Function, you don't have to deal with GitHub repos, Dockerfiles, or weird YAMLs. All you need is a Jupyter Notebook with a predict function. See our samples project for more.


Useful Links

Function is a product of NatML Inc.