xiaohongshu
xiaohongshu
hf-model-inference
Guidance for deploying HuggingFace models as inference APIs/services. This skill applies when tasks involve downloading pre-trained models from HuggingFace Hub, creating REST APIs for model inference, building Flask/FastAPI services around ML models, or setting up sentiment analysis, text classif...
Full skill instructions
This skill provides guidance for deploying HuggingFace Transformers models as inference services. Common use cases include creating REST APIs for sentiment analysis, text classification, named entity recognition, and other NLP tasks using pre-trained models from the HuggingFace Hub.
Create project directory structure
Install dependencies
transformers, torch (or tensorflow), flask/fastapipip, uv, conda) before installingpip install transformers torch flaskDownload the model
transformers library to download and cache the modelChoose the inference approach
pipeline("sentiment-analysis", model="model-name")AutoModelForSequenceClassification.from_pretrained()Implement the Flask/FastAPI service
/sentiment, /classify)Critical: Verify file completeness after writing
Implement handlers for these cases:
| Error Case | HTTP Status | Response Format |
|---|---|---|
| Missing required field | 400 | {"error": "description"} |
| Empty input text | 400 | {"error": "text cannot be empty"} |
| Invalid JSON | 400 | {"error": "invalid JSON"} |
| Wrong HTTP method | 405 | Method not allowed |
| Internal model error | 500 | {"error": "inference failed"} |
Test all response aspects systematically:
# Test with verbose output including status code
curl -w "\nHTTP Status: %{http_code}\n" -X POST http://localhost:5000/endpoint \
-H "Content-Type: application/json" \
-d '{"text": "test input"}'
Required test cases:
Verification checklist:
Problem: File content may be truncated during write operations without obvious errors. Prevention: Always read back written files immediately after creation to verify completeness.
Problem: Testing only the "happy path" without verifying error handling.
Prevention: Use curl with -w "%{http_code}" to explicitly verify HTTP status codes, not just response bodies.
Problem: Declaring task complete after tests pass without verifying implementation details. Prevention: Review actual file contents and test edge cases before marking complete.
Problem: Temporary scripts and files remain after task completion. Prevention: Track created files and clean up helper scripts that are no longer needed.
Problem: Not handling empty strings, whitespace-only input, or non-string values. Prevention: Implement validation for all input edge cases:
if not isinstance(text, str):
return jsonify({"error": "'text' must be a string"}), 400
if not text.strip():
return jsonify({"error": "'text' cannot be empty"}), 400
Standard inference response structure:
{
"label": "POSITIVE",
"score": 0.9876
}
Standard error response structure:
{
"error": "descriptive error message"
}
See references/ for additional guidance on:
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience