Fred808 commited on
Commit
b16fd96
·
verified ·
1 Parent(s): ebef92a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -41,6 +41,14 @@ with open('engagement_metrics.json', 'r') as f:
41
  # Convert engagement metrics to DataFrame
42
  engagement_df = pd.json_normalize(engagement_metrics)
43
 
 
 
 
 
 
 
 
 
44
  # Check for required columns in engagement data
45
  required_columns = ['posting_time', 'likes', 'comments', 'shares']
46
  missing_columns = [col for col in required_columns if col not in engagement_df.columns]
@@ -102,17 +110,12 @@ label_encoder = LabelEncoder()
102
  data['content_type_encoded'] = label_encoder.fit_transform(data['content_type'])
103
  data['media_type_encoded'] = label_encoder.fit_transform(data['media_type'])
104
 
105
- # Ensure 'comments' column is treated as a string column
106
- data['comments'] = data['comments'].astype(str)
107
-
108
  # Calculate sentiment for captions in the main dataset
 
109
  data['caption_sentiment'] = data['caption'].apply(lambda x: TextBlob(x).sentiment.polarity)
110
 
111
- # Calculate sentiment for comments in the main dataset
112
- data['comments_sentiment'] = data['comments'].apply(lambda x: TextBlob(x).sentiment.polarity)
113
-
114
- # Combine caption and comments sentiment (e.g., average)
115
- data['sentiment'] = (data['caption_sentiment'] + data['comments_sentiment']) / 2
116
 
117
  # Feature Engineering in the main dataset
118
  logging.info("Performing feature engineering...")
@@ -211,7 +214,7 @@ else:
211
  print(recommend_hashtags(0))
212
 
213
  # Sentiment Analysis: Audience Reactions (using main dataset)
214
- logging.info("Performing sentiment analysis on captions and comments...")
215
  data['sentiment_category'] = data['sentiment'].apply(lambda x: 'Positive' if x > 0 else 'Negative' if x < 0 else 'Neutral')
216
  logging.info("Sentiment Analysis Results:")
217
  print(data['sentiment_category'].value_counts())
 
41
  # Convert engagement metrics to DataFrame
42
  engagement_df = pd.json_normalize(engagement_metrics)
43
 
44
+ # Load solved.json (hashtags and captions)
45
+ logging.info("Loading solved.json...")
46
+ with open('solved.json', 'r') as f:
47
+ solved_data = json.load(f)
48
+
49
+ # Convert solved.json to DataFrame
50
+ solved_df = pd.json_normalize(solved_data)
51
+
52
  # Check for required columns in engagement data
53
  required_columns = ['posting_time', 'likes', 'comments', 'shares']
54
  missing_columns = [col for col in required_columns if col not in engagement_df.columns]
 
110
  data['content_type_encoded'] = label_encoder.fit_transform(data['content_type'])
111
  data['media_type_encoded'] = label_encoder.fit_transform(data['media_type'])
112
 
 
 
 
113
  # Calculate sentiment for captions in the main dataset
114
+ logging.info("Performing sentiment analysis on captions...")
115
  data['caption_sentiment'] = data['caption'].apply(lambda x: TextBlob(x).sentiment.polarity)
116
 
117
+ # Use caption sentiment as the overall sentiment
118
+ data['sentiment'] = data['caption_sentiment']
 
 
 
119
 
120
  # Feature Engineering in the main dataset
121
  logging.info("Performing feature engineering...")
 
214
  print(recommend_hashtags(0))
215
 
216
  # Sentiment Analysis: Audience Reactions (using main dataset)
217
+ logging.info("Performing sentiment analysis on captions...")
218
  data['sentiment_category'] = data['sentiment'].apply(lambda x: 'Positive' if x > 0 else 'Negative' if x < 0 else 'Neutral')
219
  logging.info("Sentiment Analysis Results:")
220
  print(data['sentiment_category'].value_counts())