===========
from fastapi import FastAPI from app.routes import review_router
app = FastAPI(title="SmartReviewAI") app.include_router(review_router, prefix="/api/reviews")
from fastapi import APIRouter, HTTPException from pydantic import BaseModel from app.services import analyze_review
review_router = APIRouter()
class ReviewInput(BaseModel): text: str
@review_router.post("/") def process_review(review: ReviewInput): try: result = analyze_review(review.text) return result except Exception as e: raise HTTPException(status_code=500, detail=str(e))
from transformers import pipeline from textwrap import shorten
sentiment_pipeline = pipeline("sentiment-analysis") summarizer_pipeline = pipeline("summarization")
def analyze_review(text: str): sentiment = sentiment_pipeline(text)[0] summary = summarizer_pipeline(text, max_length=60, min_length=25, do_sample=False)[0]['summary_text'] return { "original": text, "sentiment": sentiment['label'], "confidence": sentiment['score'], "summary": summary }
fastapi uvicorn transformers pydantic
FROM python:3.10-slim WORKDIR /app COPY . /app RUN pip install --no-cache-dir -r requirements.txt CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
A FastAPI-based backend for analyzing sentiment and summarizing product reviews using transformer-based NLP models.
- REST API to submit product reviews
- Returns:
- Sentiment (positive/negative/neutral)
- Confidence score
- AI-generated summary
- FastAPI
- Transformers (HuggingFace)
- Docker
git clone https://github.com/Takeru522/smartreview-ai.git
cd smartreview-ai
pip install -r requirements.txt
uvicorn app.main:app --reloadPOST /api/reviews/
{
"text": "This product is amazing! It really improved my workflow."
}Response:
{
"original": "This product is amazing!...",
"sentiment": "POSITIVE",
"confidence": 0.98,
"summary": "The product greatly improved the user's workflow."
}docker build -t smartreview-ai .
docker run -p 8000:8000 smartreview-aiWant to build more AI features? Fork this project and go further π