KrSharangrav
App.py andd requirements file addition
ea4634d
raw
history blame
1.15 kB
from pymongo import MongoClient
def get_mongo_client():
client = MongoClient("mongodb+srv://GMP-21-03:[email protected]/?retryWrites=true&w=majority&appName=Cluster1")
db = client["sentiment_db"]
return db["tweets"]
#### *3. Load and Process Dataset*
import pandas as pd
# Load dataset
df = pd.read_csv("C:/Users/ANOOP G ZACHARIA/Downloads/archive/sentiment140.csv")
#### *4. Sentiment Analysis using BERT-ROBERTA*
from transformers import pipeline
# Load Hugging Face model
sentiment_pipeline = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
# Function to analyze sentiment
def analyze_sentiment(text):
return sentiment_pipeline(text)[0]['label']
df["sentiment"] = df["text"].apply(analyze_sentiment)
# Save results to MongoDB
collection = get_mongo_client()
collection.insert_many(df.to_dict("records"))
#### *5. Build Streamlit Dashboard*
import streamlit as st
st.title("Sentiment Analysis Dashboard")
if st.button("Show Data"):
st.write(df)
if st.button("Show MongoDB Data"):
data = list(collection.find({}, {"_id": 0}))
st.write(pd.DataFrame(data))