https://github.com/devilkiller-ag/sentiment-analysis-api
Sentiment Analysis Server
https://github.com/devilkiller-ag/sentiment-analysis-api
Last synced: 8 months ago
JSON representation
Sentiment Analysis Server
- Host: GitHub
- URL: https://github.com/devilkiller-ag/sentiment-analysis-api
- Owner: devilkiller-ag
- License: gpl-2.0
- Created: 2025-04-23T11:25:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-24T22:10:12.000Z (about 1 year ago)
- Last Synced: 2025-07-21T09:21:24.846Z (11 months ago)
- Language: TypeScript
- Homepage: https://sentiment-analysis-api-eff1.onrender.com
- Size: 237 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sentiment Analysis Server
This is a sentiment analysis server built using Express Js and Hugging Face's Inference API. It provides an API endpoint to analyze the sentiment of given set of sentences.
Server is live at [https://sentiment-analysis-api-eff1.onrender.com](https://sentiment-analysis-api-eff1.onrender.com).
## Endpoints
### `POST /input`
**Description**: Store sentences for sentiment analysis.
#### Request Body
```json
{
"sentences": ["I love working on exciting projects.", "This experience was frustrating and disappointing."],
"webhook": "https://yourdomain.com/webhook-endpoint" // Optional
}
```
- `sentences`: Array of strings
- `webhook`: _(Optional)_ A public URL where the result will be sent once processed
#### Response
```json
{
"message": "Sentences received and stored.",
"count": 2
}
```
---
### `GET /sentiments`
**Description**: Process stored sentences, determine sentiment, and return results. Also sends webhook (if provided earlier).
#### Response
```json
[
{
"sentence": "I love working on exciting projects.",
"sentiment": "POSITIVE"
},
{
"sentence": "This experience was frustrating and disappointing.",
"sentiment": "NEGATIVE"
}
]
```
Notes:
- Only processes entries that haven't been analyzed yet (`sentiment = null`)
- If a webhook was provided, results are sent there via `POST`
---
### Webhook Delivery (Optional)
If a webhook URL was provided in `POST /input`, the server will `POST` results to that URL after processing.
#### Webhook Payload
```json
[
{
"sentence": "I love working on exciting projects.",
"sentiment": "POSITIVE"
},
{
"sentence": "This experience was frustrating and disappointing.",
"sentiment": "NEGATIVE"
}
]
```
- Sent to the webhook URL as `application/json`
- Happens right after analysis during `GET /sentiments`
## Project Setup
### Prerequisites
- Node.js (v22 or higher recommended)
- npm package manager
### Setup
1. Clone the repository:
```bash
git clone https://github.com/devilkiller-ag/sentiment-analysis-api.git
cd sentiment-analysis-api
```
2. Install dependencies:
```bash
npm install
```
3. Create a `.env` file in the root directory with your environment variables:
```bash
# Add your environment variables here
PORT=8000
DATABASE_URL="your_database_url"
HUGGINGFACE_API_KEY="your_huggingface_api_key"
```
### Development
Run the project in development mode with hot reloading:
```bash
npm run dev
```
### Scripts
- `npm run dev` - Start the development server with hot reloading
- `npm run build` - Build the TypeScript project
- `npm run start` - Run the built application in production mode
- `npm run type-check` - Check TypeScript types without emitting files
- `npm run lint` - Run ESLint to check code quality
- `npm run lint:fix` - Fix ESLint issues automatically
- `npm run format` - Format code using Prettier
- `npm run format:check` - Check if code is formatted according to Prettier
### Production
To deploy to production:
1. Build the project:
```bash
npm run build
```
2. Start the production server:
```bash
npm run start
```
### Code Quality
This project uses:
- TypeScript for type checking
- ESLint for code linting
- Prettier for code formatting
- Husky for git hooks
- lint-staged for running linters on staged files
To ensure your code meets the project standards before committing:
```bash
npm run lint
npm run format:check
```