import pandas as pd
from textblob import TextBlob
from wordcloud import WordCloud
import matplotlib.pyplot as plt


data = pd.read_csv(r"C:/Users/User/OneDrive/문서/IMDB Dataset.csv")
text_column = "review"

#  Predict Sentiment with TextBlob 
def get_sentiment(text):
    polarity = TextBlob(str(text)).sentiment.polarity
    if polarity > 0:
        return "positive"
    elif polarity < 0:
        return "negative"
    else:
        return "neutral"

data["sentiment"] = data[text_column].apply(get_sentiment)
print(data[[text_column, "sentiment"]].head())

#  Word Cloud all_text = " ".join(data[text_column].dropna())

wordcloud = WordCloud(background_color="white").generate(all_text)

plt.imshow(wordcloud)
plt.axis("off")
plt.title("Most Common Words")
plt.show()

#  Predict Your Own Sentence 
user_input = input("Enter a sentence: ")
prediction = get_sentiment(user_input)
print("Predicted Sentiment:", prediction)
#pip install pandas textblob wordcloud matplotlib 