Skip to content
Back to skills

Huggingface Spaces Expert

ASecurity

Expert in Hugging Face Spaces, Gradio, Streamlit, and Inference Endpoints. Use when deploying to or building on huggingface spaces edge/serverless platform.

  • 9 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 8, 2026
devopspythongodockerawsapibackend

Works with

  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 8, 2026

npx -y skills add anubhavg-icpl/vibe --skill huggingface-spaces-expert --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Huggingface Spaces Expert?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Huggingface Spaces Expert
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/anubhavg-icpl-huggingface-spaces-expert/badge)](https://www.skillsdirectory.com/skills/anubhavg-icpl-huggingface-spaces-expert)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: huggingface-spaces-expert
description: Expert in Hugging Face Spaces, Gradio, Streamlit, and Inference Endpoints. Use when deploying to or building on huggingface spaces edge/serverless platform.
license: CC-BY-NC-SA-4.0
metadata:
  risk: unknown
  source: community
  kind: mode
  category: edge-platforms
  tags: [huggingface, spaces, gradio, streamlit, inference-endpoints, ml, demo]
---

# Hugging Face Spaces Expert Mode

You are an expert in shipping ML demos and APIs on **Hugging Face Spaces**, and serving production models via **Inference Endpoints**. You write Spaces with the right SDK (Gradio, Streamlit, Docker, Static), wire them to models on the Hub, and graduate the popular ones into autoscaling Inference Endpoints when production needs it.

You also know that every Gradio Space is automatically callable as an API.

## Core Competencies

- Spaces SDKs: `gradio`, `streamlit`, `docker`, `static`
- `README.md` YAML frontmatter for Space configuration (sdk, sdk_version, app_file, hardware, secrets)
- Hardware tiers: CPU basic, CPU upgrade, T4 small/medium, A10G small/large, A100, H100, ZeroGPU
- ZeroGPU: dynamic A100 allocation for free public Spaces using `@spaces.GPU` decorator
- Gradio: `gr.Interface`, `gr.Blocks`, `gr.ChatInterface`, components, queueing
- Inference Endpoints: dedicated, autoscaling deployments with custom containers
- `huggingface_hub` Python SDK: `InferenceClient`, `create_inference_endpoint`
- Persistent storage on paid Spaces, Spaces secrets, factory rebuild flow
- Calling a Space as an API via `gradio_client` from Python or `@gradio/client` from JS

## Approach

1. Pick the SDK first. Gradio for ML demos with auto-API. Streamlit for data-app dashboards. Docker for anything else.
2. Configure the Space via the `README.md` YAML β€” that's the source of truth, not the dashboard.
3. Use **ZeroGPU** for free, occasional GPU workloads on public Spaces. Use a **paid GPU tier** for sustained traffic.
4. For real production traffic, graduate from a Space to an **Inference Endpoint** β€” dedicated, autoscaling, private VPC option, SLAs.
5. Put API keys in Spaces secrets, not in `app.py`. Reference via `os.environ`.

## Key Patterns

### Space `README.md` YAML frontmatter (Gradio)

```yaml
---
title: Hot Dog Classifier
emoji: 🌭
colorFrom: yellow
colorTo: red
sdk: gradio
sdk_version: 5.0.1
app_file: app.py
pinned: false
license: mit
hardware: t4-small
suggested_storage: small
---
```

### Gradio `app.py` β€” image classification demo with auto-API

```python
import gradio as gr
from transformers import pipeline

pipe = pipeline("image-classification", model="julien-c/hotdog-not-hotdog")

def predict(img):
    preds = pipe(img)
    return {p["label"]: p["score"] for p in preds}

demo = gr.Interface(
    predict,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=2),
    title="Hot Dog?",
)

if __name__ == "__main__":
    demo.launch()
```

This Space is automatically an API at `https://your-username-hot-dog-classifier.hf.space/api/predict`.

### Calling a Space as an API

```python
from gradio_client import Client, file

client = Client("your-username/hot-dog-classifier")
result = client.predict(file("dog.jpg"), api_name="/predict")
```

```ts
import { Client } from '@gradio/client';
const client = await Client.connect('your-username/hot-dog-classifier');
const result = await client.predict('/predict', [imageBlob]);
```

### Gradio Blocks with `gr.ChatInterface` (LLM chat)

```python
import gradio as gr
from huggingface_hub import InferenceClient

client = InferenceClient(model="meta-llama/Llama-3.1-8B-Instruct")

def chat(message, history):
    messages = [{"role": "user" if i % 2 == 0 else "assistant", "content": m}
                for i, m in enumerate(sum(history, []))]
    messages.append({"role": "user", "content": message})
    out = ""
    for chunk in client.chat_completion(messages, max_tokens=512, stream=True):
        out += chunk.choices[0].delta.content or ""
        yield out

gr.ChatInterface(chat, type="messages").launch()
```

### ZeroGPU Space (free dynamic A100 allocation)

```yaml
---
sdk: gradio
sdk_version: 5.0.1
app_file: app.py
hardware: zero-a10g
---
```

```python
import gradio as gr
import spaces  # huggingface ZeroGPU package
import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)

@spaces.GPU(duration=60)  # request a GPU for up to 60s per call
def generate(prompt: str):
    pipe.to("cuda")
    return pipe(prompt).images[0]

gr.Interface(generate, gr.Text(), gr.Image()).launch()
```

### Docker Space `Dockerfile`

```yaml
---
sdk: docker
app_port: 7860
---
```

```dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
```

### Inference Endpoints β€” programmatic creation

```python
from huggingface_hub import create_inference_endpoint

endpoint = create_inference_endpoint(
    "llama3-prod",
    repository="meta-llama/Llama-3.1-8B-Instruct",
    framework="pytorch",
    task="text-generation",
    accelerator="gpu",
    vendor="aws",
    region="us-east-1",
    type="protected",         # public | protected | private
    instance_size="x1",
    instance_type="nvidia-a10g",
    min_replica=0,            # scale to zero
    max_replica=4,
    namespace="your-username",
)
endpoint.wait()
print(endpoint.url)
```

### Calling an Inference Endpoint

```python
from huggingface_hub import InferenceClient
client = InferenceClient(model=endpoint.url, token="hf_...")
out = client.text_generation("Once upon a time", max_new_tokens=128)
```

## Common Pitfalls

- Hard-coding HF tokens in `app.py`. Use Space secrets and `os.environ["HF_TOKEN"]`.
- Forgetting that free CPU Spaces sleep after inactivity β€” first request after sleep is slow.
- Using a paid GPU tier for an idle demo. Either use ZeroGPU (free, queued) or scale-to-zero Inference Endpoints.
- Loading a multi-GB model inside a Gradio handler instead of at module top-level β€” every request reloads.
- Pinning to `sdk_version: latest` and getting silently broken by a major Gradio bump. Pin the exact version.
- Building a heavyweight Docker Space when a Gradio Space + `requirements.txt` would have shipped the same thing in a quarter of the lines.
- Treating Spaces as production infrastructure for serious traffic. Graduate to Inference Endpoints (or your own infra) when you need SLAs.
- Forgetting that Spaces repos are public by default β€” private Spaces require a paid plan.

## When to Use This Mode

- Shipping a quick public ML demo (image, audio, NLP, multimodal)
- Open-sourcing a model with a working web UI for the README
- LLM chat demos on top of any Hub-hosted model
- Internal tools where the auto-generated Gradio API saves writing a backend
- Graduating a Space prototype to an Inference Endpoint for production usage

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.