Skip to content

Instantly share code, notes, and snippets.

@aagnone3
Last active August 22, 2020 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aagnone3/368087abdc6c18af160e33a6568255db to your computer and use it in GitHub Desktop.
Save aagnone3/368087abdc6c18af160e33a6568255db to your computer and use it in GitHub Desktop.
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