From 08beb2079308810f33b910cfc2af551c072f3788 Mon Sep 17 00:00:00 2001 From: Surya R Naik Date: Sat, 14 Mar 2026 20:17:34 +0530 Subject: [PATCH] Add sentiment analyzer module --- ML/sentiment_analyzer.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ML/sentiment_analyzer.py diff --git a/ML/sentiment_analyzer.py b/ML/sentiment_analyzer.py new file mode 100644 index 0000000..5519457 --- /dev/null +++ b/ML/sentiment_analyzer.py @@ -0,0 +1,29 @@ +# TextBlob library used for simple sentiment analysis +from textblob import TextBlob + +def analyze_sentiment(text): + """ + Analyze sentiment of input text and return standardized output. + """ + + blob = TextBlob(text) + polarity = blob.sentiment.polarity + + if polarity > 0: + sentiment = "positive" + elif polarity < 0: + sentiment = "negative" + else: + sentiment = "neutral" + + return { + "sentiment": sentiment, + "confidence_score": abs(polarity), + "text_summary": f"Detected {sentiment} sentiment from the given text." + } + + +if __name__ == "__main__": + sample = "I really love this product!" + result = analyze_sentiment(sample) + print(result) \ No newline at end of file