Skip to content

Commit 5d1d177

Browse files
committed
Developed Streamlit app for uploading CSV files, performing sentiment analysis, and displaying recommendations
1 parent fc4e17a commit 5d1d177

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed
2.05 KB
Binary file not shown.

Web_app/app.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import streamlit as st
2+
import pandas as pd
3+
from utils import analyze_reviews, recommend_movies
4+
5+
st.title("IMDb Movie Review Analysis and Recommendation System")
6+
7+
st.sidebar.header("Upload your CSV")
8+
uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type="csv")
9+
10+
def load_data(file):
11+
try:
12+
return pd.read_csv(file, encoding='utf-8')
13+
except UnicodeDecodeError:
14+
try:
15+
return pd.read_csv(file, encoding='latin1')
16+
except UnicodeDecodeError:
17+
st.error("File encoding not supported. Please upload a CSV file with UTF-8 or Latin1 encoding.")
18+
return None
19+
20+
if uploaded_file is not None:
21+
reviews_df = load_data(uploaded_file)
22+
23+
if reviews_df is not None:
24+
st.write("Data Preview:")
25+
st.write(reviews_df.head())
26+
27+
st.write("Column Names:")
28+
st.write(reviews_df.columns.tolist())
29+
30+
if 'review' in reviews_df.columns:
31+
st.write("Sentiment Analysis:")
32+
sentiment_df, analyzed_df = analyze_reviews(reviews_df)
33+
st.write(sentiment_df)
34+
35+
st.write("Analyzed DataFrame with Sentiments:")
36+
st.write(analyzed_df.head())
37+
38+
st.write("Movie Recommendations:")
39+
recommendations = recommend_movies(analyzed_df)
40+
st.write(recommendations)
41+
else:
42+
st.error("The uploaded CSV file does not contain a 'review' column.")
43+
else:
44+
st.write("Please upload a CSV file to proceed.")

Web_app/instructions.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Installations:
2+
pip install streamlit beautifulsoup4 requests pandas scikit-learn
3+
4+
Run the Streamlit app:
5+
streamlit run app/app.py
6+
7+
8+

Web_app/utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pandas as pd
2+
from sklearn.feature_extraction.text import TfidfVectorizer
3+
from sklearn.svm import SVC
4+
from sklearn.metrics import classification_report
5+
6+
def analyze_reviews(df):
7+
vectorizer = TfidfVectorizer()
8+
X = vectorizer.fit_transform(df['review'])
9+
10+
# Dummy sentiment labels for demonstration (replace with actual sentiment labels)
11+
y = [1 if i % 2 == 0 else 0 for i in range(len(df))]
12+
13+
model = SVC()
14+
model.fit(X, y)
15+
y_pred = model.predict(X)
16+
17+
report = classification_report(y, y_pred, output_dict=True)
18+
df['sentiment'] = y_pred
19+
20+
21+
print("Analyzed DataFrame with Sentiments:")
22+
print(df.head())
23+
24+
return pd.DataFrame(report).transpose(), df
25+
26+
def recommend_movies(df):
27+
positive_reviews = df[df['sentiment'] == 1]
28+
29+
30+
print("DataFrame with Positive Reviews:")
31+
print(positive_reviews.head())
32+
33+
return positive_reviews.head(5)

0 commit comments

Comments
 (0)