This repository contains the FastAPI backend for the project Community with Sentiment Analysis and Image Moderation. The backend provides APIs for text sentiment analysis and image moderation, stores results in MongoDB, and uploads moderated images to Cloudinary.
- Text sentiment analysis using a FastAPI-based sentiment analysis microservice
- Image moderation using a FastAPI based image moderation microservice
- Image storage via Cloudinary
- Data persistence using MongoDB
- Fully async FastAPI backend
- FastAPI
- httpx (async HTTP client)
- MongoDB (pymongo)
- Cloudinary
- python-dotenv
.
├── main.py
├── .env
├── requirements.txt
└── README.md
Clone the repository:
git clone <repository-url>
cd <repository-name>
Create a virtual environment:
python -m venv venv
source venv/bin/activate
Install dependencies:
pip install -r requirements.txt
uvicorn main:app --reload
Server will run at:
http://127.0.0.1:8000
Endpoint
POST /sentiment
Request Body
{
"text": "I love this community"
}Response
{
"predicted_emotion": "positive"
}Data is stored in the texts collection with a timestamp.
Endpoint
POST /image-moderate
Form Data
file: image
Response
{
"cloudinary_url": "https://res.cloudinary.com/..."
}The moderated image is uploaded to Cloudinary and the URL is stored in the images collection.
- text
- sentiment
- full API response
- created_at
- cloudinary_url
- created_at
- External APIs must be reachable and return valid responses.
- Cloudinary uploads use the moderated image response.
- Async HTTP client improves performance under load.
For educational and academic use.