1. Learn
  2. /
  3. Courses
  4. /
  5. Deploying AI into Production with FastAPI

Connected

Exercise

Create an async sentiment analysis endpoint

You're building a social media analytics platform that needs to analyze reviews for sentiment. To handle high traffic efficiently, you need to implement an async endpoint. The sentiment analysis model is already loaded and available as sentiment_model.

Instructions

100 XP
  • Create an asynchronous POST endpoint /analyze using FastAPI app.
  • Add the keyword to call the sentiment_model asynchronously without blocking other operations.
  • Run the sentiment_model in a separate thread with the review's text, ensuring it doesn't block the event loop.