{"id":24375083,"url":"https://github.com/a-r007/sentiment-meme","last_synced_at":"2025-10-19T03:08:37.072Z","repository":{"id":269518335,"uuid":"907669294","full_name":"A-R007/Sentiment-Meme","owner":"A-R007","description":"A Flask app that leverages Groq's AI API for sentiment analysis and generates dynamic memes through Imgflip's API, tailored to the detected emotion, with robust error handling and fallback defaults.","archived":false,"fork":false,"pushed_at":"2024-12-27T04:31:24.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T05:54:09.903Z","etag":null,"topics":["flask-application","groq-api","python","sentiment-analysis"],"latest_commit_sha":null,"homepage":"https://sentiment-meme.onrender.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/A-R007.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-24T05:44:20.000Z","updated_at":"2024-12-27T04:31:27.000Z","dependencies_parsed_at":"2024-12-24T06:33:12.547Z","dependency_job_id":"e6131024-d37d-493e-af12-ba1e0946add2","html_url":"https://github.com/A-R007/Sentiment-Meme","commit_stats":null,"previous_names":["a-r007/sentiment-meme"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-R007%2FSentiment-Meme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-R007%2FSentiment-Meme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-R007%2FSentiment-Meme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/A-R007%2FSentiment-Meme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/A-R007","download_url":"https://codeload.github.com/A-R007/Sentiment-Meme/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243214803,"owners_count":20255045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask-application","groq-api","python","sentiment-analysis"],"created_at":"2025-01-19T05:53:09.987Z","updated_at":"2025-10-19T03:08:36.997Z","avatar_url":"https://github.com/A-R007.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentiment Analysis and Meme Generator Flask Application\n\nThis Flask application performs sentiment analysis on a given text input and generates a corresponding meme based on the sentiment. It integrates with Groq's AI API for sentiment analysis and Imgflip's API for meme generation. The app is designed to analyze emotions like **Happy**, **Sad**, **Angry**, **Disgusted**, **Surprised**, **Fearful**, or **Neutral** and generate a related meme dynamically.\n\n## Features\n\n- **Sentiment Analysis**: Analyze the sentiment of a given text using Groq's AI API, which classifies the text into different emotional categories.\n- **Meme Generation**: Based on the analyzed sentiment, generate a meme with a relevant template from Imgflip's API.\n- **Environment Configurations**: The application loads environment variables from a `.env` file for sensitive information like API keys.\n- **Error Handling**: The application handles exceptions gracefully and falls back to default values when necessary.\n  \n## Installation\n\nFollow these steps to set up the project locally:\n\n### 1. Clone the Repository\n\n```bash\ngit clone \u003crepo-link\u003e\ncd \u003cyour-folder\u003e\n```\n\n### 2. Set Up a Virtual Environment\n\nIt is recommended to use a virtual environment for managing dependencies.\n\nFor **Linux/macOS**:\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\n```\n\nFor **Windows**:\n\n```bash\npython -m venv .venv\n.venv\\Scripts\\activate\n```\n\n### 3. Install Dependencies\n\nInstall the required packages using `pip`.\n\n```bash\npip install -r requirements.txt\n```\n\n### 4. Create a `.env` File\n\nCreate a `.env` file in the root directory and add the following configuration:\n\n```env\nGROQ_API_KEY=your_groq_api_key\nIMGFLIP_USERNAME=your_imgflip_username\nIMGFLIP_PASSWORD=your_imgflip_password\n```\n\nReplace the placeholders with your actual API keys.\n\n### 5. Run the Flask Application\n\nYou can run the Flask application locally by executing the following command:\n\n```bash\npython app.py\n```\n\nThe application will run on port `10000` by default. You can visit it by navigating to `http://127.0.0.1:10000` in your browser.\n\n### 6. Deploy to a Cloud Provider (Optional)\n\nFor production, deploy the application to a cloud service like **Heroku**, **Render**, or **AWS**.\n\n---\n\n## How It Works\n\n### 1. **Sentiment Analysis**\nThe `analyze_sentiment` function sends a prompt to Groq's AI API. It asks Groq to analyze the sentiment of the input text and classify it into one of the following emotions:\n\n- **Happy**\n- **Sad**\n- **Angry**\n- **Disgusted**\n- **Surprised**\n- **Fearful**\n- **Neutral**\n\nThe result is returned to the Flask app.\n\n### 2. **Post-Processing Sentiment**\nThe sentiment received from the Groq API is further refined by the `post_process_sentiment` function. This function checks the presence of specific keywords in the text to adjust the sentiment if needed. For example:\n\n- If the text contains words like \"gross\", \"ew\", or \"disgusting\", the sentiment will be classified as **Disgusted**.\n- If words like \"amazing\", \"happy\", or \"joy\" are found, it will classify as **Happy**.\n\n### 3. **Meme Generation**\nAfter determining the sentiment, the app generates a meme using the Imgflip API. It selects a relevant meme template based on the sentiment and uses captions that reflect the emotional tone.\n\n- **Happy**: Uses cheerful meme templates like \"Success Kid\" and \"Doge\".\n- **Sad**: Selects sad memes like \"Crying Jordan\".\n- **Angry**: Uses memes like \"Drake\" or \"Gru\".\n- **Disgusted**: Chooses disgusted face templates.\n- **Surprised**: Uses memes like \"Pikachu Surprise\".\n- **Fearful**: Selects scared memes.\n- **Neutral**: Uses neutral memes like \"Meh\".\n\n### 4. **API Endpoints**\n\n#### **POST /analyze**\n- **Description**: Analyzes the sentiment of the provided text and generates a corresponding meme.\n- **Request Body**:\n  ```json\n  {\n    \"text\": \"I am so happy today!\"\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"sentiment\": \"Happy\",\n    \"meme_url\": \"https://i.imgflip.com/your_meme.jpg\"\n  }\n  ```\n\n---\n\n## Environment Variables\n\nThe application requires the following environment variables:\n\n- `GROQ_API_KEY`: Your API key from Groq to perform sentiment analysis.\n- `IMGFLIP_USERNAME`: Your Imgflip username for meme generation.\n- `IMGFLIP_PASSWORD`: Your Imgflip password for meme generation.\n\n---\n\n## Dependencies\n\nThis project requires the following Python libraries:\n\n- **Flask**: Web framework for building the app.\n- **requests**: HTTP library to make requests to the Imgflip API.\n- **python-dotenv**: For loading environment variables from `.env` file.\n- **groq**: Groq client to interact with Groq's AI API.\n\nThese dependencies are listed in the `requirements.txt` file.\n\n---\n\n## Logging\n\nThe application uses Python's `logging` library to log errors, especially for API calls to Groq and Imgflip. You can adjust the log level as needed during development.\n\n---\n\n## Error Handling\n\nThe application ensures that if there's an error with the Groq or Imgflip APIs, a fallback default behavior is applied:\n\n- If sentiment analysis fails, the default sentiment is **Neutral**.\n- If meme generation fails, a default meme is returned.\n\n---\n\n### Contributions\n\nFeel free to contribute to this project by submitting a pull request or opening an issue if you encounter any bugs or have suggestions for improvements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-r007%2Fsentiment-meme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-r007%2Fsentiment-meme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-r007%2Fsentiment-meme/lists"}