Spaces:
Sleeping
Sleeping
KrSharangrav
commited on
Commit
·
ea4634d
1
Parent(s):
7ba39d2
App.py andd requirements file addition
Browse files- app.py +41 -0
- requirements.txt +11 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pymongo import MongoClient
|
2 |
+
|
3 |
+
def get_mongo_client():
|
4 |
+
client = MongoClient("mongodb+srv://GMP-21-03:[email protected]/?retryWrites=true&w=majority&appName=Cluster1")
|
5 |
+
db = client["sentiment_db"]
|
6 |
+
return db["tweets"]
|
7 |
+
|
8 |
+
#### *3. Load and Process Dataset*
|
9 |
+
import pandas as pd
|
10 |
+
|
11 |
+
# Load dataset
|
12 |
+
df = pd.read_csv("C:/Users/ANOOP G ZACHARIA/Downloads/archive/sentiment140.csv")
|
13 |
+
|
14 |
+
#### *4. Sentiment Analysis using BERT-ROBERTA*
|
15 |
+
|
16 |
+
from transformers import pipeline
|
17 |
+
|
18 |
+
# Load Hugging Face model
|
19 |
+
sentiment_pipeline = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
|
20 |
+
|
21 |
+
# Function to analyze sentiment
|
22 |
+
def analyze_sentiment(text):
|
23 |
+
return sentiment_pipeline(text)[0]['label']
|
24 |
+
|
25 |
+
df["sentiment"] = df["text"].apply(analyze_sentiment)
|
26 |
+
|
27 |
+
# Save results to MongoDB
|
28 |
+
collection = get_mongo_client()
|
29 |
+
collection.insert_many(df.to_dict("records"))
|
30 |
+
|
31 |
+
#### *5. Build Streamlit Dashboard*
|
32 |
+
import streamlit as st
|
33 |
+
|
34 |
+
st.title("Sentiment Analysis Dashboard")
|
35 |
+
|
36 |
+
if st.button("Show Data"):
|
37 |
+
st.write(df)
|
38 |
+
|
39 |
+
if st.button("Show MongoDB Data"):
|
40 |
+
data = list(collection.find({}, {"_id": 0}))
|
41 |
+
st.write(pd.DataFrame(data))
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas==1.5.3
|
2 |
+
pandasai==1.4.1
|
3 |
+
pymongo==4.3.3
|
4 |
+
transformers==4.37.0
|
5 |
+
torch==2.1.0
|
6 |
+
streamlit==1.30.0
|
7 |
+
sentencepiece==0.1.99
|
8 |
+
scipy==1.10.1
|
9 |
+
huggingface_hub==0.20.3
|
10 |
+
pydantic==1.10.13
|
11 |
+
typing-extensions>=4.0
|