├── Text_20250807_a8a700.txt ├── python_20250807_e1ddde.py └── README.md /Text_20250807_a8a700.txt: -------------------------------------------------------------------------------- 1 | 🌤️ Weather Report Sentiment Analyzer 🌩️ 2 | Enter/Paste weather reports (Ctrl+D/Ctrl+Z to finish): 3 | Severe thunderstorms expected tonight with possible hail and damaging winds. 4 | Residents should take precautions and stay indoors. 5 | 6 | 📊 Analysis Results: 7 | 📝 Report: Severe thunderstorms expected tonight with possible hail and damaging winds Residents should take prec... 8 | 🎭 Primary Sentiment: NEGATIVE 9 | ✅ Confidence: 98.76% 10 | 11 | 📈 Detailed Scores: 12 | - Negative: 98.76% 13 | - Positive: 1.24% -------------------------------------------------------------------------------- /python_20250807_e1ddde.py: -------------------------------------------------------------------------------- 1 | # weather_sentiment.py 2 | from transformers import pipeline 3 | import re 4 | 5 | class WeatherSentimentAnalyzer: 6 | def __init__(self): 7 | self.classifier = pipeline( 8 | "text-classification", 9 | model="distilbert-base-uncased-finetuned-sst-2-english", 10 | top_k=None 11 | ) 12 | 13 | def clean_text(self, text): 14 | """Clean weather report text""" 15 | text = re.sub(r'[^\w\s.,;!?]', '', text) # Remove special chars 16 | text = re.sub(r'\s+', ' ', text).strip() # Remove extra spaces 17 | return text 18 | 19 | def analyze(self, report): 20 | """Analyze sentiment of a weather report""" 21 | if not report.strip(): 22 | return {"error": "Empty report provided"} 23 | 24 | cleaned_report = self.clean_text(report) 25 | results = self.classifier(cleaned_report)[0] 26 | 27 | # Find the highest confidence sentiment 28 | primary_sentiment = max(results, key=lambda x: x['score']) 29 | 30 | return { 31 | "report": cleaned_report, 32 | "sentiment": primary_sentiment['label'], 33 | "confidence": round(primary_sentiment['score'], 4), 34 | "all_scores": {res['label']: round(res['score'], 4) for res in results} 35 | } 36 | 37 | if __name__ == "__main__": 38 | analyzer = WeatherSentimentAnalyzer() 39 | 40 | print("🌤️ Weather Report Sentiment Analyzer 🌩️") 41 | print("Enter/Paste weather reports (Ctrl+D/Ctrl+Z to finish):") 42 | 43 | reports = [] 44 | try: 45 | while True: 46 | line = input() 47 | reports.append(line) 48 | except EOFError: 49 | pass 50 | 51 | full_report = " ".join(reports) 52 | 53 | if not full_report.strip(): 54 | print("\n❌ No input provided!") 55 | else: 56 | result = analyzer.analyze(full_report) 57 | print("\n📊 Analysis Results:") 58 | print(f"📝 Report: {result['report'][:100]}...") 59 | print(f"🎭 Primary Sentiment: {result['sentiment']}") 60 | print(f"✅ Confidence: {result['confidence']:.2%}") 61 | print("\n📈 Detailed Scores:") 62 | for sentiment, score in result['all_scores'].items(): 63 | print(f"- {sentiment.capitalize()}: {score:.2%}") -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Weather Report Sentiment Analyzer 2 | 3 | https://img.shields.io/badge/Python-3.8%252B-blue 4 | https://img.shields.io/badge/License-MIT-green 5 | https://img.shields.io/badge/Powered%2520by-Transformers-orange 6 | 7 | A Python tool that analyzes sentiment in weather reports using state-of-the-art NLP models. This application classifies weather forecasts as positive or negative and provides confidence scores for each sentiment category. 8 | Features 9 | 10 | 📊 Sentiment analysis of weather reports (POSITIVE/NEGATIVE) 11 | 12 | 🔢 Confidence percentages for both sentiment categories 13 | 14 | ✨ Text cleaning and preprocessing 15 | 16 | 📈 Detailed sentiment breakdown 17 | 18 | 💻 Interactive command-line interface 19 | 20 | ⚡ Fast inference using DistilBERT model 21 | 22 | Installation 23 | 24 | Clone the repository: 25 | 26 | bash 27 | 28 | git clone https://github.com/GTVSOFT/Weather-Report-Sentiment-Analyze.git 29 | cd Weather-Report-Sentiment-Analyze 30 | 31 | Install dependencies: 32 | 33 | bash 34 | 35 | pip install -r requirements.txt 36 | 37 | Usage 38 | Command Line Interface 39 | bash 40 | 41 | python weather_sentiment.py 42 | 43 | Then enter or paste your weather report text. Press Ctrl+D (Linux/Mac) or Ctrl+Z (Windows) when finished. 44 | Programmatic Usage 45 | python 46 | 47 | from weather_sentiment import WeatherSentimentAnalyzer 48 | 49 | analyzer = WeatherSentimentAnalyzer() 50 | report = "Sunny skies with a gentle breeze expected throughout the day. Perfect weather for outdoor activities." 51 | 52 | result = analyzer.analyze(report) 53 | print(f"Primary Sentiment: {result['sentiment']}") 54 | print(f"Confidence: {result['confidence']:.2%}") 55 | 56 | Example Output 57 | text 58 | 59 | 🌤️ Weather Report Sentiment Analyzer 🌩️ 60 | Enter/Paste weather reports (Ctrl+D/Ctrl+Z to finish): 61 | Severe thunderstorms expected tonight with possible hail and damaging winds. 62 | Residents should take precautions and stay indoors. 63 | 64 | 📊 Analysis Results: 65 | 📝 Report: Severe thunderstorms expected tonight with possible hail and damaging winds Residents should take prec... 66 | 🎭 Primary Sentiment: NEGATIVE 67 | ✅ Confidence: 98.76% 68 | 69 | 📈 Detailed Scores: 70 | - Negative: 98.76% 71 | - Positive: 1.24% 72 | 73 | API Response Structure 74 | 75 | The analyze() method returns a dictionary with: 76 | python 77 | 78 | { 79 | "report": "Cleaned text of the weather report", 80 | "sentiment": "PRIMARY_SENTIMENT", # Either 'POSITIVE' or 'NEGATIVE' 81 | "confidence": 0.9876, # Confidence score of primary sentiment 82 | "all_scores": { 83 | "NEGATIVE": 0.9876, 84 | "POSITIVE": 0.0124 85 | } 86 | } 87 | 88 | Dependencies 89 | 90 | Python 3.8+ 91 | 92 | transformers==4.41.2 93 | 94 | torch==2.3.0 95 | 96 | Model Information 97 | 98 | Uses the distilbert-base-uncased-finetuned-sst-2-english model from Hugging Face Transformers: 99 | 100 | Distilled version of BERT 101 | 102 | Fine-tuned on Stanford Sentiment Treebank (SST-2) 103 | 104 | 97% accuracy on SST-2 test set 105 | 106 | Lightweight and fast inference 107 | 108 | Contributing 109 | 110 | Contributions are welcome! Please open an issue or submit a pull request for any improvements. 111 | 112 | Fork the repository 113 | 114 | Create your feature branch (git checkout -b feature/your-feature) 115 | 116 | Commit your changes (git commit -am 'Add some feature') 117 | 118 | Push to the branch (git push origin feature/your-feature) 119 | 120 | Open a pull request 121 | 122 | License 123 | 124 | This project is licensed under the MIT License - see the LICENSE file for details. 125 | 126 | Author :Amos Meremu 127 | 128 | GitHub: GTVSOFT 129 | 130 | Project Repository: https://github.com/GTVSOFT/Weather-Report-Sentiment-Analyze 131 | 132 | Enjoy analyzing weather sentiments! 🌞⛅🌧️⛈️ 133 | --------------------------------------------------------------------------------