This project is a simple Sentiment Analysis Web Application that uses a FastAPI backend and an HTML, CSS, and JavaScript frontend. The backend leverages a pre-trained DistilBERT model to classify input text as positive or negative.
- Analyze sentiment (Positive/Negative) of input text.
- FastAPI backend with CORS enabled.
- Frontend built with HTML, CSS, and JavaScript to interact with the API.
- Uses Hugging Face's
distilbert-base-uncased-finetuned-sst-2-english
model for sentiment classification. - Interactive character in the frontend that changes based on the sentiment response.
- Backend: FastAPI, Transformers (Hugging Face), PyTorch
- Frontend: HTML, CSS, JavaScript
-
Clone this repository:
git clone https://github.com/Pr0-T0/Bert_sentiment_Analysis.git cd Bert_sentiment_Analysis
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install dependencies:
pip install fastapi uvicorn torch transformers pydantic
-
Run the FastAPI server:
uvicorn app:app --host 0.0.0.0 --port 8000
-
The API will be accessible at
http://localhost:8000
.
1.The frontend will be available at http://localhost:8000/static
.
-
POST
/sentiment
: Accepts a JSON object with atext
field and returns the sentiment analysis result.Request Example:
{ "text": "I love this product!" }
Response Example:
{ "sentiment": "Positive" }
/
├── backend/
│ ├── app.py # FastAPI server
├── frontend/
│ ├── index.html # Frontend UI
│ ├── styles.css # Styling
│ ├── script.js # Handles API calls and character animations
- Improve UI/UX with a better design.
- Deploy the app online.
- Extend model capabilities for more sentiment categories.
- Enhance the character animations for more emotional expressions.