--- title: SentimentAnalyzer emoji: 🦀 colorFrom: indigo colorTo: green sdk: gradio sdk_version: 5.18.0 app_file: app.py pinned: false license: apache-2.0 --- # Sentiment Analyzer ## Overview Welcome to **Sentiment Analyzer**, a text-to-text AI project developed as Part 1 of the AI Integration Project using Hugging Face pipelines and Gradio. This application takes user input in either Arabic or English, analyzes the sentiment expressed in the text, and returns a sentiment label (e.g., "1 star" to "5 stars") along with a confidence score. The goal is to demonstrate a functional, bilingual sentiment analysis pipeline integrated with an interactive Gradio interface, deployed on Hugging Face Spaces. ## Project Objectives - Build a text-to-text pipeline using a Hugging Face model for sentiment analysis. - Integrate the pipeline with a user-friendly Gradio interface. - Deploy the solution on Hugging Face Spaces for accessibility. - Ensure support for both Arabic and English inputs, showcasing bilingual capabilities. ## Implemented Pipeline - **Task**: Sentiment Analysis (Text-to-Text) - **Model**: `nlptown/bert-base-multilingual-uncased-sentiment` - **Framework**: Hugging Face Transformers - **Interface**: Gradio - **Input**: User-provided text (comments or reviews) in Arabic or English. - **Output**: Sentiment label (e.g., "1 star", "2 stars", etc.) and a confidence score (0 to 1). The pipeline processes text input, leverages a pretrained multilingual model to classify sentiment, and displays the results in an intuitive format via Gradio. ## Instructions for Using the Interface 1. **Enter Your Comment**: Type your text (e.g., a review or opinion) into the text box. 2. **Select Language**: Choose "Arabic" or "English" from the radio buttons to indicate your input language. 3. **Click Analyze**: Press the "Analyze" button to process your text. 4. **View Results**: The sentiment label (e.g., "4 stars") appears in the "Sentiment" box, and the confidence score (between 0 and 1) is shown on the slider. ### Example Inputs - English: "The product is amazing!" → "5 stars" (Positive) - Arabic: "الخدمة سيئة جداً" → "1 star" (Negative) - Try the built-in examples below the interface for a quick demo! ## Model and Pipeline Choices - **Model Selection**: The `nlptown/bert-base-multilingual-uncased-sentiment` model was chosen because: - It’s pretrained on a large, diverse dataset, enabling accurate sentiment classification. - It supports multiple languages, including Arabic and English, aligning with the bilingual requirement. - It outputs sentiment as star ratings (1 to 5), which are user-friendly and widely understood. - **Pipeline Justification**: The Hugging Face `pipeline` API simplifies integration, providing a robust, out-of-the-box solution for sentiment analysis. Paired with Gradio, it ensures an interactive experience without complex custom coding. - **Performance**: The model runs efficiently, with GPU support enabled if available (via PyTorch), ensuring quick responses for users. ## Bilingual Implementation The project fully supports both Arabic and English: - **Model Capability**: The underlying BERT-based model is multilingual and pretrained on texts including Arabic and English, allowing it to process both languages natively without additional translation steps. - **Interface Design**: The Gradio interface uses the "Tajawal" font for Arabic readability alongside Arial for English, ensuring a seamless experience for bilingual users. - **Testing**: The pipeline has been tested with Arabic and English inputs (see examples above), confirming consistent performance across both languages. No justification for excluding bilingual support is needed, as it’s fully implemented. ## Deployment - **Platform**: Hosted on Hugging Face Spaces. - **Setup**: The project uses a Gradio app (`app.py`) with dependencies listed in `requirements.txt` (`gradio`, `transformers`, `torch`). - **Access**: Publicly available via this Space’s URL—feel free to try it out! ## How to Run Locally (Optional) If you’d like to run this project locally: 1. Clone the repository from this Space. 2. Install dependencies: `pip install -r requirements.txt`. 3. Run the app: `python app.py`. 4. Open the displayed local URL in your browser. ## Contact For questions or feedback, reach out to `Tuwaigcoursega@gmail.com`. Thank you for exploring Sentiment Analyzer—we hope you find it insightful and intuitive!