|
import streamlit as st |
|
import webbrowser |
|
from nltk.sentiment.vader import SentimentIntensityAnalyzer |
|
import nltk |
|
import time |
|
import plotly.graph_objects as go |
|
|
|
|
|
st.set_page_config(page_title="Theaimart - Sentiment Analysis", layout="wide", initial_sidebar_state="auto") |
|
|
|
|
|
@st.cache_resource |
|
def download_nltk_data(): |
|
nltk.download('vader_lexicon', quiet=True) |
|
|
|
download_nltk_data() |
|
sid = SentimentIntensityAnalyzer() |
|
|
|
def analyze_sentiment(sentence): |
|
if sentence: |
|
sentiment_scores = sid.polarity_scores(sentence) |
|
highest_score = max(sentiment_scores, key=sentiment_scores.get) |
|
sentiment_dict = { |
|
'neg': 'Negative π', |
|
'neu': 'Neutral π', |
|
'pos': 'Positive π', |
|
'compound': 'Mixed π€' |
|
} |
|
highest_sentiment = sentiment_dict[highest_score] |
|
|
|
return sentiment_scores, highest_sentiment |
|
return None, None |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.main { |
|
background-color: #f0f2f6; |
|
} |
|
.stButton>button { |
|
color: #ffffff; |
|
background-color: #4CAF50; |
|
border-radius: 5px; |
|
border: none; |
|
padding: 10px 24px; |
|
transition: all 0.3s ease-in-out; |
|
} |
|
.stButton>button:hover { |
|
background-color: #45a049; |
|
transform: translateY(-2px); |
|
} |
|
.stTextInput>div>div>input { |
|
border-radius: 5px; |
|
} |
|
.stTextArea textarea { |
|
border: 2px solid #4CAF50; |
|
border-radius: 5px; |
|
} |
|
.stTextArea textarea:focus { |
|
box-shadow: 0 0 5px #4CAF50; |
|
} |
|
div.row-widget.stButton { |
|
text-align: center; |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
st.markdown( |
|
""" |
|
<h1 style='text-align: center; color: #2E86C1; animation: fadeIn 1.5s;'> |
|
Sentiment Analysis Tool |
|
</h1> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
|
|
st.markdown( |
|
""" |
|
<p style='text-align: center; font-size: 18px; animation: slideIn 1.5s;'> |
|
Analyze the sentiment of your text with our advanced AI-powered tool! |
|
</p> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
input_text = st.text_area("Enter text for sentiment analysis", height=150) |
|
|
|
|
|
col1, col2, col3 = st.columns([1,1,1]) |
|
with col2: |
|
analyze_button = st.button("Analyze") |
|
|
|
if analyze_button: |
|
with st.spinner("Analyzing sentiment..."): |
|
sentiment_scores, highest_sentiment = analyze_sentiment(input_text) |
|
|
|
if sentiment_scores: |
|
|
|
categories = ['Negative', 'Neutral', 'Positive', 'Compound'] |
|
values = [sentiment_scores['neg'], sentiment_scores['neu'], sentiment_scores['pos'], sentiment_scores['compound']] |
|
|
|
fig = go.Figure(data=go.Scatterpolar( |
|
r=values, |
|
theta=categories, |
|
fill='toself', |
|
line=dict(color='#2E86C1') |
|
)) |
|
|
|
fig.update_layout( |
|
polar=dict( |
|
radialaxis=dict(visible=True, range=[0, 1]) |
|
), |
|
showlegend=False |
|
) |
|
|
|
st.plotly_chart(fig, use_container_width=True) |
|
|
|
st.markdown(f"<h2 style='text-align: center; color: #2E86C1;'>Overall Sentiment: {highest_sentiment}</h2>", unsafe_allow_html=True) |
|
|
|
|
|
col1, col2, col3, col4 = st.columns(4) |
|
col1.metric("Negative", f"{sentiment_scores['neg']:.2f}") |
|
col2.metric("Neutral", f"{sentiment_scores['neu']:.2f}") |
|
col3.metric("Positive", f"{sentiment_scores['pos']:.2f}") |
|
col4.metric("Compound", f"{sentiment_scores['compound']:.2f}") |
|
|
|
with st.spinner("Loading ad..."): |
|
time.sleep(3) |
|
webbrowser.open("https://www.highrevenuenetwork.com/dt90hpe6y?key=472b3a55761032431e75af65c838cef4") |
|
|
|
|
|
st.markdown( |
|
""" |
|
<div style='text-align: center; padding: 20px; animation: fadeIn 2s;'> |
|
<p>Powered by Theaimart Β© 2024</p> |
|
</div> |
|
""", |
|
unsafe_allow_html=True |
|
) |