Download app.py from api-lab/fastapi-inference-template: direct link, hf CLI and curl.
- Browser
- Download file 777 Bytes
-
https://huggingface.co/api-lab/fastapi-inference-template/resolve/main/app.py
- Command line
-
hf download hf://api-lab/fastapi-inference-template/app.py
-
curl -L -o app.py https://huggingface.co/api-lab/fastapi-inference-template/resolve/main/app.py
777 Bytes
| # -*- coding: utf-8 -*- | |
| """app.py | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/14li2A2e6uXyOUJztPqqlallXTtuGJTGl | |
| """ | |
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from transformers import pipeline | |
| # Init FastAPI | |
| app = FastAPI(title="FastAPI Inference Template", version="1.0") | |
| # Example model (can be swapped out easily) | |
| model = pipeline("sentiment-analysis") | |
| # Request schema | |
| class InferenceRequest(BaseModel): | |
| text: str | |
| # Root check | |
| def root(): | |
| return {"status": "ok", "message": "Inference API is live"} | |
| # Predict endpoint | |
| def predict(request: InferenceRequest): | |
| result = model(request.text) | |
| return {"input": request.text, "output": result} |