iamshukla commited on
Commit
3ef88e9
ยท
1 Parent(s): ce8af5b

feat: Redesign Gradio UI

Browse files
Files changed (4) hide show
  1. LICENSE +21 -0
  2. README.md +77 -7
  3. app.py +65 -0
  4. requirements.txt +5 -0
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 [Your Name]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,12 +1,82 @@
1
  ---
2
- title: Sentiment Analysis
3
- emoji: ๐Ÿ†
4
- colorFrom: pink
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 5.35.0
8
  app_file: app.py
9
- pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Sentiment Reveal
3
+ emoji: ๐Ÿ“Š
 
 
4
  sdk: gradio
5
+ sdk_version: "4.37.2"
6
  app_file: app.py
7
+ license: mit
8
  ---
9
 
10
+ # Sentiment Reveal
11
+
12
+ **Sentiment Reveal** is a powerful and intuitive sentiment analysis application designed to analyze product reviews and other text data from eCommerce platforms. It supports multiple languages and provides detailed sentiment feedback, helping businesses understand customer feedback more effectively.
13
+
14
+ ![Sentiment Reveal Screenshot](https://i.imgur.com/your-screenshot.png) <!-- Replace with an actual screenshot -->
15
+
16
+ ## ๐ŸŒŸ Features
17
+
18
+ - **Multilingual Support:** Analyzes text in English, Dutch, German, French, Italian, and Spanish.
19
+ - **Detailed Sentiment Analysis:** Classifies sentiment into five levels: Very Negative, Negative, Neutral, Positive, and Very Positive.
20
+ - **Confidence Score:** Provides a confidence score for each prediction.
21
+ - **User-Friendly Interface:** Simple and clean interface built with Gradio.
22
+ - **Theme Support:** Optimized for both light and dark themes.
23
+
24
+ ## ๐Ÿš€ How It Works
25
+
26
+ This application is powered by `nlptown/bert-base-multilingual-uncased-sentiment`, a pre-trained BERT model fine-tuned for sentiment analysis on a 1-5 star rating scale. The model is capable of understanding and interpreting nuances in the text across multiple languages.
27
+
28
+ ## ๐Ÿ› ๏ธ Getting Started
29
+
30
+ ### Prerequisites
31
+
32
+ - Python 3.7+
33
+ - `pip` for package management
34
+
35
+ ### Installation
36
+
37
+ 1. **Clone the repository:**
38
+ ```bash
39
+ git clone https://github.com/your-username/SentimentReveal.git
40
+ cd SentimentReveal
41
+ ```
42
+
43
+ 2. **Create and activate a virtual environment (recommended):**
44
+ ```bash
45
+ python -m venv venv
46
+ source venv/bin/activate # On Windows, use `venv\Scripts\activate`
47
+ ```
48
+
49
+ 3. **Install the dependencies:**
50
+ ```bash
51
+ pip install -r requirements.txt
52
+ ```
53
+
54
+ ### Running the Application
55
+
56
+ Once the dependencies are installed, you can run the application with the following command:
57
+
58
+ ```bash
59
+ python app.py
60
+ ```
61
+
62
+ The application will be available at a local URL (e.g., `http://127.0.0.1:7860`).
63
+
64
+ ## ๐Ÿ’ผ Benefits
65
+
66
+ - **Understand Customer Feedback:** Quickly gauge customer opinions from reviews.
67
+ - **Improve Products & Services:** Identify areas for improvement based on sentiment.
68
+ - **Monitor Brand Reputation:** Keep track of how your brand is perceived across different languages.
69
+
70
+ ## ๐Ÿค Contributing
71
+
72
+ Contributions are welcome! If you have any suggestions or find any bugs, please open an issue or submit a pull request.
73
+
74
+ ## ๐Ÿ“„ License
75
+
76
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
77
+
78
+ ---
79
+
80
+ ### Deploy
81
+
82
+ If you would like to deploy this app on your own server or customize it further for your needs, feel free to reach out.
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained sentiment analysis model
5
+ sentiment_model = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
6
+
7
+ # Function to analyze sentiment
8
+ def analyze_sentiment(text):
9
+ # Get sentiment predictions
10
+ result = sentiment_model(text)
11
+ label = result[0]['label']
12
+ score = result[0]['score']
13
+
14
+ # Map labels to scores for the Label component
15
+ label_mapping = {
16
+ '1 star': 'Very Negative',
17
+ '2 stars': 'Negative',
18
+ '3 stars': 'Neutral',
19
+ '4 stars': 'Positive',
20
+ '5 stars': 'Very Positive'
21
+ }
22
+
23
+ # Return a dictionary of labels and their confidences
24
+ return {label_mapping[label]: score}
25
+
26
+ # Custom CSS for appealing colors on dark and light themes
27
+ css = """
28
+ body, .gradio-container {background-color: #f4f4f4; font-family: 'Arial'; color: #333;}
29
+ .gr-input {border-radius: 10px; border: 2px solid #999; padding: 10px; background-color: #fff; color: #333;}
30
+ .gr-button {background-color: #3498db; color: white; border: none; padding: 10px 20px; border-radius: 10px; cursor: pointer;}
31
+ .gr-button:hover {background-color: #2980b9;}
32
+ .output-text {font-size: 18px; color: #333;}
33
+ footer {display: none !important;}
34
+ /* Dark theme */
35
+ @media (prefers-color-scheme: dark) {
36
+ body, .gradio-container {background-color: #2c3e50; color: #ecf0f1;}
37
+ .gr-input {background-color: #34495e; color: #ecf0f1; border: 2px solid #999;}
38
+ .gr-button {background-color: #2980b9;}
39
+ .gr-button:hover {background-color: #1abc9c;}
40
+ .output-text {color: #ecf0f1;}
41
+ }
42
+ """
43
+
44
+ # Create Gradio interface with enhanced UI and updated description
45
+ interface = gr.Interface(
46
+ fn=analyze_sentiment,
47
+ inputs=gr.Textbox(
48
+ lines=5,
49
+ placeholder="Enter a marketplace review or sentence here...",
50
+ label="Input Review",
51
+ ),
52
+ outputs=gr.Label(num_top_classes=5),
53
+ title="Sentiment Reveal",
54
+ description=(
55
+ "Analyze the sentiment of product reviews in English, Dutch, German, French, Italian, and Spanish. Focused Sentiment Analysis for eCommerce."
56
+ ),
57
+ examples=[["This product is amazing! I highly recommend it."],
58
+ ["I'm very disappointed with this purchase."],
59
+ ["The product was okay, not great but not terrible."]],
60
+ allow_flagging="never",
61
+ css=css,
62
+ )
63
+
64
+ # Launch the app with sharing enabled
65
+ interface.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers==4.42.3
2
+ gradio==4.37.2
3
+ torch==2.7.1
4
+ torchvision
5
+ torchaudio