Define the environment
The first thing we’ll do is define the environment that our app will run on. For this example, we’re building a Sentiment Analysis model using Huggingface. First, you’ll define aRuntime with an Image.
We’re going to be defining which packages to install in the runtime, and the hardware this code will run on.
app.py
Inference function
Now, we’ll write some code to predict the sentiment of a given text prompt. Our function takes keyword arguments, as(**inputs).
run.py
Adding a REST API
To prepare to deploy the API, we’ll add arest_api decorator to our inference function.
Add the following decorator to your predict_sentiment function.
app.py
app.py file will look like this:
app.py
Deploying the app
To deploy the model, enter your terminal andcd to the directory you’re
working on.
Then, run the following:
Show Logs
Show Logs