Walid-Ahmed commited on
Commit
622a2c6
1 Parent(s): bc70c30

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +82 -1
README.md CHANGED
@@ -10,4 +10,85 @@ pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  license: apache-2.0
11
  ---
12
 
13
+ # Sentiment Analyzer
14
+
15
+ This project provides a web-based tool to analyze the sentiment of reviews using a pre-trained model from Hugging Face's `transformers` library. Users can upload a text file containing reviews, and the tool will display a DataFrame with the sentiment analysis results and a pie chart visualizing the sentiment distribution.
16
+
17
+ ## Features
18
+
19
+ - **Sentiment Analysis**: Uses a pre-trained model to classify the sentiment of each review as positive or negative.
20
+ - **File Upload**: Allows users to upload a text file containing reviews.
21
+ - **DataFrame Display**: Shows a DataFrame with the original reviews, sentiment labels, and confidence scores.
22
+ - **Pie Chart Visualization**: Displays a pie chart showing the percentage of positive and negative reviews.
23
+
24
+ ## Requirements
25
+
26
+ - Python 3.6 or higher
27
+ - `transformers` library
28
+ - `pandas` library
29
+ - `matplotlib` library
30
+ - `gradio` library
31
+
32
+ ## Installation
33
+
34
+ 1. Clone the repository:
35
+ ```bash
36
+ git clone https://github.com/your-username/sentiment-analyzer.git
37
+ cd sentiment-analyzer
38
+ ```
39
+
40
+ 2. Install the required libraries:
41
+ ```bash
42
+ pip install transformers pandas matplotlib gradio
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ 1. Save your reviews in a text file named `reviews.txt`, with each review on a new line.
48
+
49
+ 2. Run the script:
50
+ ```bash
51
+ python app.py
52
+ ```
53
+
54
+ 3. Open your web browser and go to the local server URL provided by Gradio (usually `http://127.0.0.1:7860`).
55
+
56
+ 4. Upload the `reviews.txt` file.
57
+
58
+ 5. The tool will display a DataFrame with the sentiment analysis results and a pie chart visualizing the sentiment distribution.
59
+
60
+ ## Code Explanation
61
+
62
+ - **read_reviews_to_dataframe**: Reads reviews from a text file and converts them into a pandas DataFrame.
63
+ - **analyzer**: Applies sentiment analysis to a given text and returns the label and score.
64
+ - **evaluate_reviews**: Adds sentiment evaluation to each review in the DataFrame and splits it into 'Sentiment' and 'Score' columns.
65
+ - **create_pie_chart**: Creates and saves a pie chart showing the distribution of sentiments.
66
+ - **process_reviews**: Processes the uploaded file, evaluates reviews, and generates the pie chart.
67
+ - **gradio_interface**: Function for Gradio interface that processes the file and returns the DataFrame and chart path.
68
+
69
+ ## Example
70
+
71
+ 1. Prepare a text file `reviews.txt` with the following content:
72
+ ```
73
+ The product quality is excellent!
74
+ The battery life is awful.
75
+ Very satisfied with the purchase.
76
+ Will not buy again, very disappointed.
77
+ ```
78
+
79
+ 2. Run the script:
80
+ ```bash
81
+ python app.py
82
+ ```
83
+
84
+ 3. Upload `reviews.txt` via the Gradio interface.
85
+
86
+ 4. View the DataFrame and pie chart displaying the sentiment analysis results.
87
+
88
+ ## License
89
+
90
+ This project is licensed under the MIT License.
91
+
92
+ ## Author
93
+
94
+ This tool was created by **Walid Ahmed**.