0% found this document useful (0 votes)
9 views2 pages

23

This document contains a Python script that implements a sentiment analysis tool using the NLTK library and a GUI built with Tkinter. It analyzes user input for sentiment and provides feedback based on the analysis, displaying results in a message box. The script includes a typewriter effect for text output and a simple animation for terminal display, although the latter is not utilized in the GUI context.

Uploaded by

harisekarr6157
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

23

This document contains a Python script that implements a sentiment analysis tool using the NLTK library and a GUI built with Tkinter. It analyzes user input for sentiment and provides feedback based on the analysis, displaying results in a message box. The script includes a typewriter effect for text output and a simple animation for terminal display, although the latter is not utilized in the GUI context.

Uploaded by

harisekarr6157
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import sys

import time
import random
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer
import tkinter as tk
from tkinter import messagebox

# Download the VADER lexicon for sentiment analysis


nltk.download('vader_lexicon')

# Initialize SentimentIntensityAnalyzer
sia = SentimentIntensityAnalyzer()

# Function for typewriter effect


animation = "|/-\\"
def typewriter_effect(text, max_delay=0.1, min_delay=0.3):
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(random.uniform(min_delay, max_delay))
print()

# Function to display an animation in the terminal (not needed in GUI but kept for completeness)
def show_animation():
for i in range(35):
sys.stdout.write("\r" + animation[i % len(animation)])
sys.stdout.flush()
time.sleep(0.1)

# Function to analyze sentiment


def analyze_sentiment(text):
sentiment_scores = sia.polarity_scores(text)
compound_score = sentiment_scores['compound']
if compound_score >= 0.05:
sentiment = 'Positive'
response_text = "Thank you for your positive review"
elif compound_score <= -0.05:
sentiment = 'Negative'
response_text = "Sorry for your bad experience"
else:
sentiment = 'Neutral'
response_text = "Thank you for your review"
return sentiment, sentiment_scores, response_text
# Function for GUI interaction
def on_submit():
user_text = input_text.get("1.0", "end-1c")
if user_text.lower() == 'end':
root.destroy()
else:
sentiment, scores, response = analyze_sentiment(user_text)
messagebox.showinfo("Sentiment Analysis Result", f"Sentiment: {sentiment}\n{response}\
nScores: {scores}")

# Create the main window


root = tk.Tk()
root.title("Sentiment Analysis GUI")
root.geometry("400x300")

# Create a text input widget


input_label = tk.Label(root, text="Enter your review:")
input_label.pack(pady=10)

input_text = tk.Text(root, height=5, width=40)


input_text.pack(pady=5)

# Create a submit button


submit_button = tk.Button(root, text="Analyze", command=on_submit)
submit_button.pack(pady=10)

# Run the main loop


root.mainloop()

You might also like