Spaces:
Sleeping
A newer version of the Gradio SDK is available:
5.34.2
title: Text Sentiment Classifier
emoji: π§
sdk: gradio
app_file: app.py
Text-Sentiment-Classifier-API
This project is a simple REST API for sentiment analysis built with FastAPI and HuggingFace Transformers. It uses the distilbert-base-uncased-finetuned-sst-2-english model to classify English text as positive, negative or (rarely) neutral, and it returns a confidence score.
π Features
RESTful API with FastAPI
Pre-trained BERT-based sentiment model
JSON input and output
Interactive Swagger UI at /docs
π¦ Model
The API uses:
distilbert-base-uncased-finetuned-sst-2-english
A lightweight version of BERT fine-tuned on the SST-2 dataset for sentiment classification.
Example
Request:
POST /predict { "text": "I absolutely love this product!" }
Response:
{ "sentiment": "positive", "confidence": 0.9981 }
π File Structure
.
βββ main.py # API implementation
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
π How to Use
- Enter any English sentence in the input box
- Click Submit
- View the sentiment label and confidence
π How to Deploy on Hugging Face Spaces
Create a Hugging Face account
Sign up at https://huggingface.co/joinCreate a new Space Go to https://huggingface.co/spaces and click Create new Space
Fill out the form
- Space name: text-sentiment-api (or your choice)
- SDK: Gradio
- Visibility: Public or Private
Upload the files
- app.py
- requirements.txt
- README.md (this file)
Wait for the build Hugging Face will automatically install dependencies and launch the app
Access your app