File size: 4,529 Bytes
b94f68c
a8c7e21
b94f68c
 
 
 
 
 
 
 
a8c7e21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
title: 'Multilingual Sentiment Analyzer'
emoji: πŸ“‰
colorFrom: gray
colorTo: pink
sdk: docker
pinned: false
---

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
🌍 Multilingual Sentiment Analyzer
A comprehensive AI-powered sentiment analysis application with explainable AI features (SHAP & LIME) supporting multiple languages.
πŸš€ Features

Multi-language Support: Auto-detect or manually select from English, Chinese, Spanish, French, German, Swedish
Advanced Analysis: SHAP and LIME explainable AI integration
Batch Processing: Analyze multiple texts simultaneously with parallel processing
Interactive Visualizations: Real-time charts and dashboards with Plotly
History Management: Track and export analysis history
Multiple Themes: Customizable color themes for visualizations
File Upload: Support for CSV and TXT file uploads
Export Functionality: Export results in CSV and JSON formats

πŸ“ Project Structure
sentiment_analyzer/
β”œβ”€β”€ config.py              # Configuration settings
β”œβ”€β”€ models.py               # Model management & sentiment engine
β”œβ”€β”€ analysis.py             # SHAP/LIME explainable AI
β”œβ”€β”€ visualization.py        # Plotly visualizations
β”œβ”€β”€ data_utils.py           # Data processing & history management
β”œβ”€β”€ app.py                  # Application logic
β”œβ”€β”€ main.py                 # Gradio interface & startup
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ Dockerfile             # Docker configuration
└── README.md              # This file
πŸ›  Installation
Option 1: Local Installation
bash# Clone the repository
git clone <repository-url>
cd sentiment_analyzer

# Install dependencies
pip install -r requirements.txt

# Download NLTK data
python -c "import nltk; nltk.download('stopwords'); nltk.download('punkt')"

# Run the application
python main.py
Option 2: Docker
bash# Build the Docker image
docker build -t sentiment-analyzer .

# Run the container
docker run -p 7860:7860 sentiment-analyzer
Option 3: Hugging Face Spaces

Create a new Space on Hugging Face
Select "Docker" as the SDK
Upload all project files
The app will automatically deploy

🎯 Usage
Single Text Analysis

Navigate to the "Single Analysis" tab
Enter your text in any supported language
Select language (or use Auto Detect)
Choose visualization theme
Configure preprocessing options
Click "Analyze"

Advanced Analysis (SHAP/LIME)

Go to "Advanced Analysis" tab
Enter text for explainable AI analysis
Adjust number of samples (50-300)
Click "SHAP Analysis" or "LIME Analysis"
View feature importance visualizations

Batch Processing

Switch to "Batch Analysis" tab
Upload a file or enter multiple texts (one per line)
Configure analysis settings
Click "Analyze Batch"
View summary statistics and detailed results

History & Analytics

Open "History & Analytics" tab
View comprehensive analysis dashboard
Export data in CSV or JSON format
Clear history when needed

πŸ”§ Configuration
Edit config.py to customize:

Model Settings: Change supported models and languages
Processing Limits: Adjust batch sizes and memory limits
UI Themes: Modify color schemes
Cache Settings: Configure caching parameters

πŸ“Š Supported Models

English: CardiffNLP Twitter RoBERTa
Multilingual: CardiffNLP XLM-RoBERTa
Chinese: UER RoBERTa Chinese

🎨 Themes

Default: Green/Red/Orange
Ocean: Blue/Orange/Cyan
Dark: Darker variants
Rainbow: Purple/Pink/Red

⚑ Performance Features

Model Caching: LRU cache for efficient model management
Parallel Processing: Multi-threaded batch analysis
Memory Optimization: Automatic cleanup and GPU management
Lazy Loading: Models loaded on-demand

πŸ› Troubleshooting
Common Issues

SHAP/LIME Errors: Reduce sample size or text length
Memory Issues: Lower batch size or enable text cleaning
Model Loading: Check internet connection for model downloads
Port Conflicts: Change port in main.py if 7860 is occupied

Performance Tips

Use GPU if available for faster processing
Enable text cleaning for better preprocessing
Reduce sample sizes for faster explainable AI analysis
Clear history periodically to save memory

πŸ“„ License
This project is open source and available under the MIT License.
🀝 Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
πŸ“ž Support
For support and questions, please open an issue in the repository.

Built with ❀️ using Gradio, Transformers, SHAP, LIME, and Plotly