Hugging Face: Serverless Inference action - This topic describes using the Hugging Face : Serverless Inference action to leverage the power of Hugging Face models for various NLP tasks.
This topic describes using the Hugging Face: Serverless Inference
action to leverage the power of Hugging Face models for various NLP tasks.
Before you begin
Note: The examples and graphics provided on this page are for
representation purposes only and might not reflect accurately for your specific instance. We
do not assume responsibility for their maintenance or
accuracy.
You must have the Bot creator role to use the Hugging Face: Authentication action in a bot.
Ensure that you have the necessary credentials to send a request and have
included Hugging Face: Authentication action before calling Hugging Face: Serverless Inference action.
Procedure
Log in to your Hugging Face account.
Select a Model: Navigate to the Hugging Face model library (Hugging Face
models).Search for and select a model that supports Serverless
Inference. Supported model types include:
Text Generation
Text to Image Generation
Image to Text Generation
Text to Audio Generation
For this example, openai-community/gpt2 model is used for Text
Generation.
Copy the following from the model's Serverless Inference request format.
Model Id: Copy the model ID from the API URL in the request
format. In this case, it would be
openai-community/gpt2.
Request Payload: Use the JSON provided in the model's Serverless
Inference format.
Modify the prompt within the JSON to fit your specific use case. For
example: you can modify the above JSON as
follows:
{"inputs": "Explain quantum computing in simple terms."}
Watch the following video to learn how to access the
above request format of a model.
Log in to the Control Room.
From the Actions pane, select AI > Hugging Face > Serverless Inference and place it in the canvas.
Enter or select the following fields:
In the Model Id field, paste the
Model ID copied from your Hugging Face.
In the Request Payload field, paste the
Request Payload copied from your Hugging Face.
Optional: Data File Path: Data File Path specifies the download
location for image/audio files generated by your model.
Enter Default as the session name to limit the session to the
current session.
Save the response to a variable. In this example, the response is saved
to HuggingFace-response.
Click Run to start the automation.
You can read the value of the field by printing the response in a Message
boxaction. In this example, HuggingFace-response
prints the response.
Tip: To maintain multiple chats in the same
bot, you will need to create multiple sessions with different names or variables.
The response of the above automation is as
follows:
You can parse the output JSON using the JSON package to derive the
desired output.
More examples
The following automation showcases text to image, image to text, and
text to audio generation capabilities using the Hugging Face: Serverless Inference action. Each example is
explained in detail in the subsequent sections.
Text to Image
The following example demonstrates text to image generation capability using the Hugging Face: Serverless Inference action:
Note: Provide a Data File Path to which the
image gets saved to.
Image to Text
The following example demonstrates image to text generation capability using the Hugging Face: Serverless Inference action:
Note: Convert the image to a Base64 format using Base64
Conversion >> Base64 Encode action
before feeding it to the model. The model requires the image in this format to
accurately generate text.
Text to Audio
The following examples demonstrates text to audio generation capability using the Hugging Face: Serverless Inference action:
Note: Provide a Data File Path with an
extension to which the input prompt text in the Request
payload is converted to an audio format.