Skip to content

Instantly share code, notes, and snippets.

@aagnone3
Last active August 22, 2020 21:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
fastapi-sentiment-routes
from fastapi import FastAPI
from fastapi_sentiment import sentiment_analysis
from fastapi_sentiment.models import (
SentimentDocument,
SentimentScoring,
Message
)
app = FastAPI()
@app.get("/", response_model=Message, status_code=200)
def read_root() -> Message:
return {
'message': 'Hello World'
}
@app.get("/health", response_model=Message, status_code=200)
async def get_health() -> Message:
return {
'message': 'Still kicking'
}
@app.post("/sentiment", response_model=SentimentScoring, status_code=200)
async def get_sentiment(document: SentimentDocument) -> SentimentScoring:
return sentiment_analysis.get_sentiment(document.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment