import pandas as pd
from transformers import pipeline
import numpy as np
from sklearn.metrics import accuracy_score

# Load dataset
df = pd.read_csv("data/tweets.csv")
tweets = df['tweet'].values
true_labels = df['sentiment'].values

# Initialize Hugging Face sentiment analysis pipeline (BERT-based)
classifier = pipeline('sentiment-analysis')

# Predict sentiments
predictions = []
for tweet in tweets:
    result = classifier(tweet)[0]
    pred = 1 if result['label'] == 'POSITIVE' else 0
    predictions.append(pred)

# Calculate accuracy
accuracy = accuracy_score(true_labels, predictions)
print(f"Accuracy: {accuracy * 100:.2f}%")

