| |
| |
| |
|
|
| import streamlit as st |
| import joblib |
| from PIL import Image |
| import threading |
| import time |
| import os |
|
|
| |
| try: |
| from playsound import playsound |
| SOUND_ENABLED = True |
| except Exception: |
| SOUND_ENABLED = False |
|
|
| |
| |
| |
| model = joblib.load("sentiment_model.pkl") |
| vectorizer = joblib.load("tfidf_vectorizer.pkl") |
|
|
| |
| |
| |
| def play_sound_limited(sound_file, duration=3): |
| if not SOUND_ENABLED: |
| return |
| def play(): |
| try: |
| playsound(sound_file) |
| except Exception: |
| pass |
| t = threading.Thread(target=play) |
| t.start() |
| time.sleep(duration) |
| os.system("taskkill /IM wmplayer.exe /F >nul 2>&1") |
|
|
| |
| |
| |
| st.set_page_config(page_title="TweetPulse AI 💬", page_icon="💫", layout="centered") |
|
|
| st.markdown(""" |
| <h1 style='text-align:center; color:#6a0dad;'>💫 TweetPulse AI - Sentiment Analyzer 💫</h1> |
| <h4 style='text-align:center; color:gray;'>Analyze tweet emotions instantly ⚡</h4> |
| """, unsafe_allow_html=True) |
|
|
| |
| tweet = st.text_area( |
| "✍️ Type your tweet below:", |
| placeholder="e.g. I absolutely loved this movie! 🎬", |
| height=120, |
| help="Type any sentence or tweet to analyze its emotion." |
| ) |
|
|
| |
| |
| |
| if st.button("🔍 Analyze Sentiment"): |
| if tweet.strip() == "": |
| st.warning("⚠️ Please type something to analyze.") |
| else: |
| tweet_vector = vectorizer.transform([tweet]) |
| prediction = model.predict(tweet_vector)[0] |
|
|
| if prediction == "positive": |
| img = Image.open("positive.png") |
| st.image(img, width=180) |
| st.success("🎉 Sentiment Detected: **Positive 😍**") |
| play_sound_limited("positive.mp3", duration=3) |
|
|
| elif prediction == "negative": |
| img = Image.open("negative.png") |
| st.image(img, width=180) |
| st.error("💢 Sentiment Detected: **Negative 😡**") |
| play_sound_limited("negative.mp3", duration=3) |
|
|
| else: |
| img = Image.open("neutral.png") |
| st.image(img, width=180) |
| st.info("😐 Sentiment Detected: **Neutral 😐**") |
| play_sound_limited("neutral.mp3", duration=3) |
|
|
| |
| |
| |
| st.markdown("---") |
| st.caption("💜 Created by **Isneha Varshney** | Powered by TweetPulse AI") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|