Skip to content

Mimi97-aqua/sentiment_analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentiment Analysis

Overview

This API provides endpoints for sentiment analysis for the following sources:

  • Web page URLs
  • Uploaded documents of file types .txt and .csv
  • Directly provided sentences

The different sentiment types are:

Sentiment Type Polarity Value (p)
Postive p > 0
Negative p < 0
Neutral p = 0

It uses:

  • Flask: for the web framework
  • TextBlob: for sentiment analysis
  • NewsPaper: for downloading articles from the web
pip install nltk, flask, newspaper3k, textblob

Note: This API is hosted here. You can use this link to test the endpoints as an alternative to local setup.

Installation

  1. Clone this repository
git clone https://github.com/Mimi97-aqua/sentiment_analysis.git
cd <repo-dir>
  1. Create and activate virtual environment
python -m venv .venv
source .venv/Scripts/activate  # On Windows OS
  1. Install required packages

pip install -r requirements.txt

Configuration

  1. Setup the upload folder
  • The upload folder is used for temporarily storing uploaded documents. The files in this folder are deleted after processing is over in order to free up space.

  • Ensure the app/tmp directory exists or modify the upload_folder path in the code to a directory of your choice.

Usage

  1. Start the Flask application

To achieve this, run main.py

  1. Endpoints

Base endpoint: /api

  • GET /

    • Returns a welcome message.
  • GET /web

    • Query paramter: url (string)
    • Description: Analyzes the sentiment from the text of the provided webpage URL
    • Response:
    {
      "status": "success",
      "sentiment": "positive" // or "negative" or "neutral"
    }
  • POST /doc

    • Form data: file (file)
    • Description: Analyzes sentiment from the text of the uploaded document.
    • Response:
     {
        "status": "success",
        "sentiment": "positive" // or "negative" or "neutral"
     }
  • GET /sentence

    • Query parameter: sentence (string)
    • Description: Analyzes the sentiment from a provided sentence
    • Response:
       {
          "status": "success",
          "sentiment": "positive" // or "negative" or "neutral"
       }

Error Handling

This API responds with appropriate error messages and status codes for issues such as missing parameters or invalid file types.

Contributing

  1. Fork this repository and clone your fork.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request with a clear description of your changes.

About

Detects the sentiment from a piece of text passed in either as a doc, web url, or sentence

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages