Skip to content

Instantly share code, notes, and snippets.

@nbertagnolli
Created June 20, 2021 21:56
Show Gist options
  • Save nbertagnolli/806710563d5c55832a10ea0eb194d7ab to your computer and use it in GitHub Desktop.
Save nbertagnolli/806710563d5c55832a10ea0eb194d7ab to your computer and use it in GitHub Desktop.
from fastapi import FastAPI
from pydantic import BaseModel
# Initialize the FastAPI App
app = FastAPI()
# Create a Data Model so FastAPI can read the data from the request.
class Review(BaseModel):
text: str
@app.post("/review/predict")
async def movie_sentiment_prediction(review: Review):
"""Accept post requests and predicts positive or negative review"""
response = dict()
if "love" in review.text.lower():
response["sentiment"] = "positive"
else:
response["sentiment"] = "negative"
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment