This project is a Social Media Performance Insights application that allows users to analyze engagement data from social media platforms. The app leverages Langflow for workflow and GPT integration to provide actionable insights and uses Astra DB (DataStax) to store and query the dataset. Users can interact with the data through a chat-like interface on the frontend, built using Next.js and make the insights more comprehensible.
- Frontend: Next.js
- Backend: Next.js API Routes
- Workflow Management: Langflow
- Database: DataStax Astra DB
- Styling: Tailwind CSS with ShadCN
The following Python code generates a dummy dataset simulating social media engagement. The dataset includes columns for post_id, post_type, likes, shares, comments, engagement_rate, and created_at.
python import random import uuid import pandas as pd from datetime import datetime, timedelta
POST_TYPES = ["carousel", "reels", "static_image"] NUM_RECORDS = 500
def generate_engagement_data(post_type): base_likes = random.randint(50, 200) base_shares = random.randint(5, 50) base_comments = random.randint(3, 25)
# Engagement based on post type
if post_type == "carousel":
likes = base_likes * 1.2
shares = base_shares * 1.1
comments = base_comments * 1.3
elif post_type == "reels":
likes = base_likes * 1.5
shares = base_shares * 1.4
comments = base_comments * 1.8
else: # static_image
likes = base_likes
shares = base_shares
comments = base_comments
total_engagement = likes + shares + comments
engagement_rate = total_engagement / (likes + 1) # Prevent divide-by-zero
return int(likes), int(shares), int(comments), round(engagement_rate, 2)
data = [] start_date = datetime.now() - timedelta(days=NUM_RECORDS)
for _ in range(NUM_RECORDS): post_id = str(uuid.uuid4()) post_type = random.choice(POST_TYPES) likes, shares, comments, engagement_rate = generate_engagement_data(post_type) created_at = (start_date + timedelta(days=random.randint(0, 30))).strftime("%Y-%m-%d %H:%M:%S") data.append([post_id, post_type, likes, shares, comments, engagement_rate, created_at])
columns = ["post_id", "post_type", "likes", "shares", "comments", "engagement_rate", "created_at"] df = pd.DataFrame(data, columns=columns)
df.to_csv('mock_engagement_data.csv', index=False) df.to_json('mock_engagement_data.json', orient='records', date_format='iso')
The engagement rate is a metric used to measure the effectiveness of a social media post. It is calculated as the ratio of total user interactions (likes, shares, and comments) to a scaled audience size. For this project, the formula is defined as:
\`python
total_engagement = likes + shares + comments
engagement_rate = total_engagement / (likes + 1) # Prevent divide-by-zero
\`
- total_engagement: Sum of all user interactions, including likes, shares, and comments.
- engagement_rate: Calculated by dividing total_engagement by (likes + 1). This adjustment ensures no division-by-zero errors when likes are very low.
- Chat-Like Interface: Users can query insights in natural language.
- Engagement Insights: Analyze the performance of different post types (e.g., Reels, Carousels, Static Images).
- Actionable Recommendations: GPT generates suggestions for optimizing social media strategy.
- Clone the repository and install dependencies using npm install.
- Set up environment variables for Langflow and Astra DB integration.
- FLOW_ID
- LANGFLOW_ID
- APPLICATION_TOKEN
- Run the Next.js application locally using npm run dev.
- Access the application at http://localhost:3000.
Enjoy analyzing your social media performance and optimizing your strategy!