import streamlit as st import webbrowser from nltk.sentiment.vader import SentimentIntensityAnalyzer import nltk import time import plotly.graph_objects as go # Set page config at the very beginning st.set_page_config(page_title="Theaimart - Sentiment Analysis", layout="wide", initial_sidebar_state="auto") # Download necessary NLTK data @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 # Custom CSS to improve the app's appearance st.markdown(""" """, unsafe_allow_html=True) # App title with animation st.markdown( """

Sentiment Analysis Tool

""", unsafe_allow_html=True ) # Animated description st.markdown( """

Analyze the sentiment of your text with our advanced AI-powered tool!

""", unsafe_allow_html=True ) input_text = st.text_area("Enter text for sentiment analysis", height=150) # Center the Analyze button 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: # Create a radar chart for 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"

Overall Sentiment: {highest_sentiment}

", unsafe_allow_html=True) # Display detailed scores 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) # Simulate a delay for loading webbrowser.open("https://www.highrevenuenetwork.com/dt90hpe6y?key=472b3a55761032431e75af65c838cef4") # Footer st.markdown( """

Powered by Theaimart © 2024

""", unsafe_allow_html=True )