### Install OpenCode GitHub App
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/guides/github-actions-code-review.md
Navigate to your local clone of your GitHub repository and run the setup command to install the OpenCode GitHub App. This command initiates an interactive setup process.
```bash
cd your-repository
opencode github install
```
--------------------------------
### Install pylance and pyarrow
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/datasets-lance.md
Install the necessary libraries to get started with Lance and Hugging Face integration.
```bash
pip install pylance pyarrow
```
--------------------------------
### Python Client: Quick Start
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-api-endpoints.md
Install the Gradio client and make a prediction on a public Space.
```APIDOC
## Install
```bash
pip install --upgrade gradio_client
```
## Quick Start Example
```python
from gradio_client import Client
client = Client("abidlabs/en2fr", token="hf_...")
result = client.predict("Hello, world!", api_name="/predict")
print(result) # "Bonjour, le monde!"
```
```
--------------------------------
### Install Flair using pip
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/flair.md
Install the Flair library using pip. This is a one-line command for quick setup.
```bash
$ pip install -U flair
```
--------------------------------
### Clone and Run Evidence App Locally
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-sdks-docker-evidence.md
Clone your Evidence app from Hugging Face Spaces, install dependencies, and start the development server to make local edits.
```bash
git clone https://huggingface.co/spaces/your-username/your-space-name
cd your-space-name
npm install
npm run sources
npm run dev
```
--------------------------------
### Launch llama.cpp Server
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/agents-local.md
Start a llama.cpp server to host a model and provide an OpenAI-compatible API. Ensure you have llama.cpp installed and a compatible model downloaded.
```bash
llama-server -hf ggml-org/gemma-4-26b-a4b-it-GGUF:Q4_K_M
```
--------------------------------
### Conversational Widget Example
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/models-widgets-examples.md
Set up the conversational widget with an initial user input and an example title.
```yaml
widget:
- text: "Hey my name is Julien! How are you?"
example_title: "Julien"
- text: "Hey my name is Clara! How are you?"
example_title: "Clara"
```
--------------------------------
### Install Gradio Client
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-api-endpoints.md
Install the Python client library for interacting with Gradio Spaces.
```bash
pip install --upgrade gradio_client
```
--------------------------------
### Clone ML-Agents Repository
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/ml-agents.md
Clone the ML-Agents repository from GitHub and install the necessary packages. This is the initial setup step for using ML-Agents.
```bash
# Clone the repository
git clone https://github.com/Unity-Technologies/ml-agents
# Go inside the repository and install the package
cd ml-agents
pip3 install -e ./ml-agents-envs
pip3 install -e ./ml-agents
```
--------------------------------
### Install OpenAI SDK
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/guides/gpt-oss.md
Install the official OpenAI SDK for your project. This allows you to interact with the API.
```bash
pip install openai
```
```bash
npm install openai
```
--------------------------------
### Setup SageMaker Environment and S3 Bucket
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/source/tutorials/sagemaker-sdk/sagemaker-sdk-quickstart.md
Initialize a SageMaker session, retrieve the default S3 bucket, and get the IAM execution role. This setup is crucial for running notebooks within SageMaker.
```python
import sagemaker
sess = sagemaker.Session()
sagemaker_session_bucket = None
if sagemaker_session_bucket is None and sess is not None:
sagemaker_session_bucket = sess.default_bucket()
role = sagemaker.get_execution_role()
sess = sagemaker.Session(default_bucket=sagemaker_session_bucket)
```
--------------------------------
### Install OpenCLIP
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/open_clip.md
Install the open_clip_torch library using pip. This is the first step to using OpenCLIP models.
```bash
$ pip install open_clip_torch
```
--------------------------------
### Install Hugging Face Skills (Gemini CLI)
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/agents-skills.md
Install Hugging Face Skills for Gemini CLI by cloning the repository. Ensure you consent to the installation.
```bash
gemini extensions install https://github.com/huggingface/skills.git --consent
```
--------------------------------
### Install SageMaker SDK
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/notebooks/sagemaker-sdk/fine-tune-trl-cli/sagemaker-notebook.ipynb
Installs the SageMaker Python SDK. Use --upgrade --quiet for unattended installations.
```python
%pip install sagemaker --upgrade --quiet
```
--------------------------------
### Question Answering Widget Example
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/models-widgets-examples.md
Set up the question-answering widget with a question, context, and an example title.
```yaml
widget:
- text: "What's my name?"
context: "My name is Clara and I live in Berkeley."
example_title: "Name"
- text: "Where do I live?"
context: "My name is Sarah and I live in London"
example_title: "Location"
```
--------------------------------
### Install BERTopic
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/bertopic.md
Install BERTopic using pip. This is the first step to using the library.
```bash
pip install bertopic
```
--------------------------------
### Install llama.cpp with Winget
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/gguf-llamacpp.md
Use this command to install llama.cpp on Windows systems using Winget.
```bash
winget install llama.cpp
```
--------------------------------
### Install mlx-image
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/mlx-image.md
Install the mlx-image library using pip. This is the first step to using the library.
```bash
pip install mlx-image
```
--------------------------------
### Install SetFit
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/setfit.md
Install the SetFit library using pip. This command ensures you have the latest version.
```bash
pip install -U setfit
```
--------------------------------
### Install and Run tiny-agents
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/agents-libraries.md
Install the tiny-agents library for JavaScript or Python and run an agent using its ID.
```bash
npx @huggingface/tiny-agents run "agent/id"
```
```bash
pip install "huggingface_hub[mcp]"
tiny-agents run "agent/id"
```
--------------------------------
### Install spacy-huggingface-hub
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spacy.md
Install the library using pip. This command is required before using the CLI or Python functions.
```bash
pip install spacy-huggingface-hub
```
--------------------------------
### Install paddlenlp
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/paddlenlp.md
Install the paddlenlp library using pip. This is the first step to using PaddleNLP models.
```bash
pip install -U paddlenlp
```
--------------------------------
### Install and Run Doc Builder
Source: https://github.com/huggingface/hub-docs/blob/main/README.md
Installs the `hf-doc-builder` and related dependencies, then runs the preview command for the Hub documentation. Ensure you replace `{YOUR_PATH}` with the actual path to your local `hub-docs` repository.
```bash
pip install hf-doc-builder
pip install black watchdog
doc-builder preview hub {YOUR_PATH}/hub-docs/docs/hub/ --not_python_module
```
--------------------------------
### Install Sample Factory
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/sample-factory.md
Install the sample-factory library using pip. This library is known to work on Linux and MacOS, with no current Windows support.
```bash
pip install sample-factory
```
--------------------------------
### Install Git Xet Extension via Homebrew
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/xet/using-xet-storage.md
Install the Git Xet extension on macOS using Homebrew. After installation, run 'git xet install' to complete the setup.
```bash
brew install git-xet
```
```bash
git xet install
```
--------------------------------
### Text Generation Widget Example
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/models-widgets-examples.md
Provide a starting text for the text generation widget and an example title.
```yaml
widget:
- text: "My name is Julien and I like to"
example_title: "Julien"
- text: "My name is Merve and my favorite"
example_title: "Merve"
```
--------------------------------
### Initialize Project with uv
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/guides/image-editor.md
Create a new project directory and initialize it using the `uv` package manager. This sets up a basic project structure with a `pyproject.toml` file.
```bash
mkdir image-editor-app
cd image-editor-app
uv init
```
--------------------------------
### Get Statistics for Latitude and Longitude
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/datasets-duckdb-select.md
Use the SUMMARIZE command to get statistics for specified columns. This example retrieves aggregates for latitude and longitude from a Parquet dataset.
```bash
SUMMARIZE SELECT latitude, longitude FROM 'hf://datasets/jamescalam/world-cities-geo@~parquet/default/train/0000.parquet';
```
```text
┌─────────────┬─────────────┬──────────────┬─────────────┬───────────────┬────────────────────┬────────────────────┬────────────────────┬────────────────────┬────────────────────┬───────┬─────────────────┐
│ column_name │ column_type │ min │ max │ approx_unique │ avg │ std │ q25 │ q50 │ q75 │ count │ null_percentage │
│ varchar │ varchar │ varchar │ varchar │ int64 │ varchar │ varchar │ varchar │ varchar │ varchar │ int64 │ decimal(9,2) │
├─────────────┼─────────────┼──────────────┼─────────────┼───────────────┼────────────────────┼────────────────────┼────────────────────┼────────────────────┼────────────────────┼───────┼─────────────────┤
│ latitude │ DOUBLE │ -54.8 │ 67.8557214 │ 7324 │ 22.5004568364307 │ 26.770454684690925 │ 6.089858461951687 │ 29.321258648324747 │ 44.90191158328915 │ 9083 │ 0.00 │
│ longitude │ DOUBLE │ -175.2166595 │ 179.3833313 │ 7802 │ 14.699333721953098 │ 63.93672742608224 │ -6.877990418604821 │ 19.12963979385393 │ 43.873513093419966 │ 9083 │ 0.00 │
└─────────────┴─────────────┴──────────────┴─────────────┴───────────────┴────────────────────┴────────────────────┴────────────────────┴────────────────────┴────────────────────┴───────┴─────────────────┘
```
--------------------------------
### First Agent Call with Web Search Tool
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/notebooks/sagemaker-sdk/neuron-agent-inf/sagemaker-notebook.ipynb
Demonstrates how to initialize an agent with the web_search tool and make a query. Requires a configured model.
```python
agent = Agent(model=model, tools=[web_search])
response = agent("What are AWS Neuron devices?")
```
--------------------------------
### Install Adapters Library
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/adapters.md
Install the Adapters library using pip. This is the first step to using adapters with Hugging Face models.
```bash
pip install adapters
```
--------------------------------
### Start Giskard ML Worker
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-sdks-docker-giskard.md
Use this command to start the Giskard ML worker. Ensure you have all model dependencies installed in your Python environment. Replace placeholders with your actual API key, Space URL, and Space token.
```bash
giskard worker start -d -k GISKARD-API-KEY -u https://XXX.hf.space --hf-token GISKARD-SPACE-TOKEN
```
--------------------------------
### JAX GPU Setup
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-gpus.md
Instructions for setting up JAX to utilize CUDA-compatible GPU packages.
```APIDOC
## JAX GPU Setup
### Description
If you use JAX, you need to specify the URL that contains CUDA compatible packages. Please, add the following lines to your `requirements.txt` file:
### Requirements
```
-f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
jax[cuda11_pip]
jaxlib
```
### Verification
After installation, you can verify the setup by running the following code and checking the output in your Space logs:
### Code Example
```python
import jax
print(f"JAX devices: {jax.devices()}")
# Expected output: JAX devices: [StreamExecutorGpuDevice(id=0, process_index=0)]
print(f"JAX device type: {jax.devices()[0].device_kind}")
# Expected output: JAX device type: Tesla T4
```
```
--------------------------------
### Token Classification API Usage
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/tasks/token-classification.md
Example of how to use the token classification API. Specify the model and input text to get token-level classifications.
```python
from huggingface_hub import InferenceClient
client = InferenceClient("Babelscape/wikineural-multilingual-ner")
text = "My name is Wolfgang and I live in Berlin."
result = client.token_classification(text)
print(result)
```
--------------------------------
### Install hf-mount with Homebrew
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/storage-buckets-access.md
Install the `hf-mount` tool using Homebrew. This is the first step to mounting buckets as a local filesystem.
```bash
brew install hf-mount
```
--------------------------------
### Install huggingface_hub Library
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/datasets-streaming.md
Install the huggingface_hub library to enable streaming capabilities. It's recommended to use the latest version.
```bash
pip install -U huggingface_hub
```
--------------------------------
### Deploy Hugging Face Model with SageMaker JumpStart
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/source/tutorials/jumpstart/jumpstart-quickstart.md
Deploys a specified Hugging Face model using SageMaker JumpStart and retrieves example payloads for testing. Ensure you have the SageMaker Python SDK v2 installed (`pip install "sagemaker<3.0.0"`).
```python
from sagemaker.jumpstart.model import JumpStartModel
model = JumpStartModel(model_id="huggingface-llm-qwen2-5-14b-instruct")
example_payloads = model.retrieve_all_examples()
predictor = model.deploy()
for payload in example_payloads:
response = predictor.predict(payload.body)
print("Input:\n", payload.body[payload.prompt_key])
print("Output:\n", response[0]["generated_text"], " \n\n===============\n")
```
--------------------------------
### Text Generation with Python
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/tasks/text-generation.md
Example of how to perform text generation using the Hugging Face Python library. This snippet requires the 'transformers' library to be installed.
```python
from transformers import pipeline
generator = pipeline('text-generation', model='HuggingFaceBio/Carbon-3B')
result = generator('The future of AI is', max_length=50, num_return_sequences=1)
```
--------------------------------
### Install Gradio Client (JavaScript)
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-api-endpoints.md
Install the JavaScript client library using npm or include it via a CDN.
```bash
npm i @gradio/client
```
```html
```
--------------------------------
### HTTP Request for Xet Token
Source: https://github.com/huggingface/hub-docs/blob/main/docs/xet/auth.md
Example of an HTTP GET request to obtain a Xet read token, including the necessary Host and Authorization headers.
```http
GET /api/models/black-forest-labs/FLUX.1-dev/xet-read-token/main
Host: huggingface.co
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
--------------------------------
### Feature Extraction using Python
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/tasks/feature-extraction.md
Example of how to perform feature extraction using the Hugging Face Python client. This snippet requires the 'transformers' library to be installed.
```python
from transformers import pipeline
feature_extractor = pipeline("feature-extraction", model="thenlper/gte-large")
result = feature_extractor("The input text to embed.")
print(result)
```
--------------------------------
### Launch Claude Code with hf-claude
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/integrations/claude-code.md
Launch Claude Code using the `hf claude` command after installing the extension. This command will guide you through model and provider selection.
```bash
hf claude
```
--------------------------------
### Python Example for ASR
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/tasks/automatic-speech-recognition.md
This Python snippet demonstrates how to transcribe audio using the Hugging Face Inference API. You'll need to install the 'requests' library. Replace 'YOUR_API_TOKEN' with your token.
```python
import requests
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
API_TOKEN = "YOUR_API_TOKEN"
def query(filename):
with open(filename, "rb") as f:
data = f.read()
headers = {"Authorization": f"Bearer {API_TOKEN}"}
response = requests.post(API_URL, headers=headers, data=data)
return response.json()
output = query("/path/to/audio.wav")
print(output)
```
--------------------------------
### Train mlx-image Model
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/mlx-image.md
Example of training a model using mlx-image, demonstrating data loading, model creation, optimizer setup, and the training loop. Requires setting up datasets and dataloaders.
```python
import mlx.nn as nn
import mlx.optimizers as optim
from mlxim.model import create_model
from mlxim.data import LabelFolderDataset, DataLoader
train_dataset = LabelFolderDataset(
root_dir="path/to/train",
class_map={0: "class_0", 1: "class_1", 2: ["class_2", "class_3"]}
)
train_loader = DataLoader(
dataset=train_dataset,
batch_size=32,
shuffle=True,
num_workers=4
)
model = create_model("resnet18") # pretrained weights loaded from HF
optimizer = optim.Adam(learning_rate=1e-3)
def train_step(model, inputs, targets):
logits = model(inputs)
loss = mx.mean(nn.losses.cross_entropy(logits, target))
return loss
model.train()
for epoch in range(10):
for batch in train_loader:
x, target = batch
train_step_fn = nn.value_and_grad(model, train_step)
loss, grads = train_step_fn(x, target)
optimizer.update(model, grads)
mx.eval(model.state, optimizer.state)
```
--------------------------------
### Install PEFT Library
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/peft.md
Install the PEFT library using pip. This is the first step to using PEFT models.
```bash
$ pip install peft
```
--------------------------------
### Initialize Hugging Face InferenceClient
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/guides/image-editor.md
Import necessary libraries and initialize the `InferenceClient` from `huggingface_hub`. This example uses the `fal-ai` provider for fast image processing and requires your Hugging Face API key from environment variables.
```python
import os
import gradio as gr
from huggingface_hub import InferenceClient
import io
# Initialize the client with fal-ai provider for fast image processing
client = InferenceClient(
provider="fal-ai",
api_key=os.environ["HF_TOKEN"],
)
```
--------------------------------
### Compatible Dockerfile for Spaces Dev Mode
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-dev-mode.md
This Dockerfile installs necessary packages like bash, git, wget, and curl, sets the working directory to /app, copies the application code, installs npm dependencies, ensures the /app directory is owned by user 1000, and sets the CMD to start a Node.js application. It is designed to be compatible with Spaces Dev Mode.
```Dockerfile
FROM node:19-slim
RUN apt-get update && \
apt-get install -y \
bash \
git git-lfs \
wget curl procps \
htop vim nano && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --link ./ /app
RUN npm i
RUN chown 1000 /app
USER 1000
CMD ["node", "index.js"]
```
--------------------------------
### Alternative InferenceClient Providers
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/guides/image-editor.md
Demonstrates how to initialize the `InferenceClient` with different providers like `replicate` or use `auto` for automatic selection. This allows experimentation with various inference backends.
```python
client = InferenceClient(provider="replicate", api_key=os.environ["HF_TOKEN"])
client = InferenceClient(provider="auto", api_key=os.environ["HF_TOKEN"]) # Automatic selection
```
--------------------------------
### Analyze Research Paper with Structured Output (Hugging Face Hub)
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/guides/structured-output.md
Use the InferenceClient to get structured JSON output for research paper analysis. Ensure your HF_TOKEN environment variable is set. This example defines a Pydantic model for the expected schema.
```python
import os
import json
from huggingface_hub import InferenceClient
from pydantic import BaseModel
from typing import List
# Set your Hugging Face token
# export HF_TOKEN="your_token_here"
def analyze_paper_structured():
"""Complete example of structured output for research paper analysis."""
# Initialize the client
client = InferenceClient(
provider="cerebras", # or use "auto" for automatic selection
api_key=os.environ["HF_TOKEN"],
)
# Example paper text (you can replace this with any research paper)
paper_text = """
Title: Attention Is All You Need
Abstract: The dominant sequence transduction models are based on complex recurrent
or convolutional neural networks that include an encoder and a decoder. The best
performing models also connect the encoder and decoder through an attention mechanism.
We propose a new simple network architecture, the Transformer, based solely on
attention mechanisms, dispensing with recurrence and convolutions entirely.
Experiments on two machine translation tasks show these models to be superior
in quality while being more parallelizable and requiring significantly less time to train.
Introduction: Recurrent neural networks, long short-term memory and gated recurrent
neural networks in particular, have been firmly established as state of the art approaches
in sequence modeling and transduction problems such as language modeling and machine translation.
"""
# Define the response format (JSON Schema)
class PaperAnalysis(BaseModel):
title: str
abstract_summary: str
response_format = {
"type": "json_schema",
"json_schema": {
"name": "PaperAnalysis",
"schema": PaperAnalysis.model_json_schema(),
"strict": True,
},
}
# Define your messages
messages = [
{
"role": "system",
"content": "Extract paper title and abstract summary."
},
{
"role": "user",
"content": paper_text
}
]
# Generate structured output
response = client.chat_completion(
messages=messages,
response_format=response_format,
model="Qwen/Qwen3-32B",
)
# The response is guaranteed to match your schema
structured_data = response.choices[0].message.content
# Parse and display results
analysis = json.loads(structured_data)
print(f"Title: {analysis['title']}")
print(f"Abstract Summary: {analysis['abstract_summary']}")
if __name__ == "__main__":
# Make sure you have set your HF_TOKEN environment variable
analyze_paper_structured()
```
--------------------------------
### Install Hugging Face and SageMaker Libraries
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/source/tutorials/sagemaker-sdk/sagemaker-sdk-quickstart.md
Install the required Hugging Face libraries, SageMaker SDK (v2), and PyTorch. Ensure you use `sagemaker<3.0.0` for compatibility with existing tutorials.
```bash
pip install "sagemaker<3.0.0" "transformers==4.26.1" "datasets[s3]==2.10.1" --upgrade
```
--------------------------------
### Get Hugging Face LLM and TEI Image URIs
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/source/dlcs/available.md
Use this utility function to retrieve the correct image URIs for Text Generation Inference (TGI) and Text Embeddings Inference (TEI) containers, supporting GPU and CPU configurations. Ensure you are using SageMaker Python SDK v2 by installing `"sagemaker<3.0.0"`.
```python
from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
print(f"TGI GPU: {get_huggingface_llm_image_uri('huggingface')}")
print(f"TEI GPU: {get_huggingface_llm_image_uri('huggingface-tei')}")
print(f"TEI CPU: {get_huggingface_llm_image_uri('huggingface-tei-cpu')}")
print(f"TGI Neuron: {get_huggingface_llm_image_uri('huggingface-neuronx')}")
```
--------------------------------
### Install Data Designer
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/datasets-data-designer.md
Install the Data Designer package using pip. This is the first step before using the framework.
```bash
pip install data-designer
```
--------------------------------
### Install Dependencies for Gradio Space
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-sdks-gradio.md
Add these dependencies to your requirements.txt file to install necessary libraries for your Gradio Space. The Spaces runtime will handle the installation.
```text
transformers
torch
```
--------------------------------
### Build llama.cpp from source
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/gguf-llamacpp.md
Navigate to the llama.cpp directory and build the project. Hardware-specific flags like `-DGGML_CUDA=1` can be added for GPU support.
```bash
cd llama.cpp
cmake -B build # optionally, add -DGGML_CUDA=ON to activate CUDA
cmake --build build --config Release
```
--------------------------------
### Install Hugging Face CLI
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/jobs-quickstart.md
Install the Hugging Face CLI using curl, Homebrew, or uv. Ensure you have the necessary tools installed on your system.
```bash
>>> curl -LsSf https://hf.co/cli/install.sh | bash
```
```bash
>>> brew install hf
```
```bash
>>> uv tool install hf
```
--------------------------------
### Initialize HuggingFaceVLM for Video Understanding
Source: https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/integrations/visionagents.md
Set up the HuggingFaceVLM for real-time video understanding. Configure parameters like frames per second (fps) and frame buffer duration.
```python
from vision_agents.plugins import huggingface, getstream, deepgram
from vision_agents.core import Agent, User
agent = Agent(
edge=getstream.Edge(),
agent_user=User(name="AI Assistant", id="agent"),
instructions="You are a helpful visual assistant.",
llm=huggingface.VLM(
model="Qwen/Qwen2-VL-7B-Instruct",
fps=1,
frame_buffer_seconds=10,
),
)
```
--------------------------------
### Install and Authenticate Hugging Face CLI
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/agent-traces.md
Install the Hugging Face CLI using the provided script and log in to your account. This is a prerequisite for uploading traces.
```bash
curl -LsSf https://hf.co/cli/install.sh | bash
hf auth login
```
--------------------------------
### Install pyspark_huggingface
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/datasets-spark.md
Install the library to read and write Hugging Face Datasets in PySpark. This also installs necessary dependencies like huggingface_hub and pyarrow.
```bash
pip install pyspark_huggingface
```
--------------------------------
### Connect to ZenML Server CLI
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-sdks-docker-zenml.md
Use this CLI command to connect your local machine to a ZenML server deployed on HuggingFace Spaces. Ensure you replace the placeholder with your actual Space's Direct URL. The 'username' and 'password' parameters are also shown.
```shell
zenml connect --url '' --username='default' --password=''
```
--------------------------------
### Uninstall Git Xet on Windows via Installer
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/xet/using-xet-storage.md
Uninstall the Git Xet extension on Windows if it was installed using the MSI installer. This is done through the Windows Apps settings.
```bash
git xet uninstall
```
--------------------------------
### Define TruthfulQA Task for Lighteval
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/notebooks/sagemaker-sdk/evaluate-llm-lighteval/sagemaker-notebook.ipynb
Writes a tasks.txt file to specify the evaluation task, dataset, and few-shot examples for Lighteval. This example configures the TruthfulQA benchmark with 0 few-shot examples.
```python
with open("scripts/tasks.txt", "w") as f:
f.write(f"lighteval|truthfulqa:mc|0|0")
```
--------------------------------
### Initialize and run an Agent in Python
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/agents-sdk.md
Initialize an Agent with a specific model, provider, and server configuration. Use the agent.run() method to interact with the agent and stream responses.
```python
from huggingface_hub import Agent
import asyncio
agent = Agent(
model="Qwen/Qwen2.5-72B-Instruct",
provider="novita",
servers=[
{
"type": "sse",
"url": "https://evalstate-flux1-schnell.hf.space/gradio_api/mcp/sse"
}
]
)
async def main():
async for chunk in agent.run("Generate an image of a sunset"):
if hasattr(chunk, 'choices'):
delta = chunk.choices[0].delta
if delta.content:
print(delta.content, end="")
asyncio.run(main())
```
--------------------------------
### Install and Run hf-speedtest
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/datasets-downloading.md
Install the `hf-speedtest` CLI extension and run it to test your download speed from Hugging Face's CDN. This helps in understanding your network throughput.
```bash
hf extensions install julien-c/hf-speedtest
hf speedtest
```
--------------------------------
### Question Answering Request Example
Source: https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/source/reference/inference-toolkit.md
Example JSON payload for question answering task.
```json
{
"inputs": {
"question": "What is used for inference?",
"context": "My Name is Philipp and I live in Nuremberg. This model is used with sagemaker for inference."
}
}
```
--------------------------------
### Create a Giskard Client
Source: https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-sdks-docker-giskard.md
Initialize a Giskard Client to establish a connection with your Giskard Space. Ensure you have the correct URL, API key, and HF token.
```python
from giskard import GiskardClient
url = "https://user_name-space_name.hf.space"
api_key = "gsk-xxx"
hf_token = "xxx"
# Create a giskard client to communicate with Giskard
client = GiskardClient(url, api_key, hf_token)
```