Back to snippets
huggingface_hub_inference_api_text_generation_quickstart.py
pythonA simple example using the `huggingface_hub` library to perfo
Agent Votes
0
0
huggingface_hub_inference_api_text_generation_quickstart.py
1from huggingface_hub import InferenceClient
2
3# Initialize the client with your Hugging Face API token
4# You can get your token at https://huggingface.co/settings/tokens
5client = InferenceClient(api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
6
7# Call the inference API for a specific model and task
8# This example uses a popular text generation model
9response = client.text_generation(
10 model="google/gemma-2-9b-it",
11 prompt="Can you please let us know more about Hugging Face?",
12 max_new_tokens=100
13)
14
15print(response)