Skip to main content

Transformers FastAPI Kit

Biblioteca Python com Hugging Face Transformers para análise de sentimento e chatbot conversacional via Hugging Face Inference API, acompanhada por um servidor FastAPI.

Instalação

pip install "transformers-fastapi-kit[api]"

Chatbot conversacional

A classe HuggingFaceChatbot usa a API oficial de inferência da Hugging Face. Cria um token em https://huggingface.co/settings/tokens com permissão de inferência e configura-o sem o colocar no código.

Windows PowerShell:

$env:HF_TOKEN = "hf_o_teu_token"

macOS/Linux:

export HF_TOKEN="hf_o_teu_token"

Uso em Python:

from transformers_fastapi_kit import HuggingFaceChatbot

bot = HuggingFaceChatbot()
print(bot.chat("Olá! Explica o que podes fazer."))

Para manter contexto, envia o histórico:

history = [{"role": "user", "content": "Olá"}, {"role": "assistant", "content": "Olá!"}]
reply = bot.chat("Podes ajudar-me com Python?", history=history)

O modelo por defeito é HuggingFaceH4/zephyr-7b-beta; podes escolher outro modelo de chat compatível com HuggingFaceChatbot(model_name="...").

API REST

python -m uvicorn app.main:app --host 0.0.0.0 --port 8000

Endpoints: GET /health, POST /predict e POST /chat. A documentação Swagger fica em /docs.

Pedido de chat:

curl -X POST http://127.0.0.1:8000/chat \\
  -H "Content-Type: application/json" \\
  -d '{"message":"Olá! Quem és?","history":[]}'

Recursos incluídos

O pacote inclui transformers_fastapi_kit/resources/TUTORIAL.md e transformers_fastapi_kit/resources/transformers-fastapi-kit-starter.zip.

from importlib.resources import files
resources = files("transformers_fastapi_kit") / "resources"
print(resources / "TUTORIAL.md")
print(resources / "transformers-fastapi-kit-starter.zip")

Documentação pública: https://transformers-ynoszgzv.manus.space

Desenvolvimento

pip install -e ".[api,dev]"
pytest
python -m build
python -m twine check dist/*

Licença

MIT

Metadata

Release files for transformers-fastapi-kit 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for transformers-fastapi-kit 0.2.0
File Size Uploaded Provenance Actions
transformers_fastapi_kit-0.2.0.tar.gz 14.7 kB Without provenance Details for transformers_fastapi_kit-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for transformers-fastapi-kit 0.2.0
File Interpreter ABI Platform Actions
transformers_fastapi_kit-0.2.0-py3-none-any.whl Python 3 none any Details for transformers_fastapi_kit-0.2.0-py3-none-any.whl

Total release size: 28.4 kB

Release files / transformers_fastapi_kit-0.2.0.tar.gz

Download URL transformers_fastapi_kit-0.2.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
358a43f0dc18e2b8ed7d0b0b0d509eab3322e5041653833873c841291333f0b4
BLAKE2b-256 checksum
How to use checksums
9eb8058a588def74bd015cd7e475266706e1052c65c311453bcc2f81e7c90a5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / transformers_fastapi_kit-0.2.0-py3-none-any.whl

Download URL transformers_fastapi_kit-0.2.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
662ca4c27b2b16784f109981a93e15bc501507a06f4aea45a7033b319a409874
BLAKE2b-256 checksum
How to use checksums
20ae128fdfdf0495c25c0a08d23d379a60ba5fe547ace9dea856d247a552d14d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for transformers-fastapi-kit 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page