File size: 777 Bytes
19c66ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- 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
@app.get("/")
def root():
    return {"status": "ok", "message": "Inference API is live"}

# Predict endpoint
@app.post("/predict")
def predict(request: InferenceRequest):
    result = model(request.text)
    return {"input": request.text, "output": result}