| | |
| | """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 |
| |
|
| | |
| | app = FastAPI(title="FastAPI Inference Template", version="1.0") |
| |
|
| | |
| | model = pipeline("sentiment-analysis") |
| |
|
| | |
| | class InferenceRequest(BaseModel): |
| | text: str |
| |
|
| | |
| | @app.get("/") |
| | def root(): |
| | return {"status": "ok", "message": "Inference API is live"} |
| |
|
| | |
| | @app.post("/predict") |
| | def predict(request: InferenceRequest): |
| | result = model(request.text) |
| | return {"input": request.text, "output": result} |