import streamlit as st import joblib import numpy as np # Load model and vectorizer model = joblib.load('logistic_regression_model.pkl') vect = joblib.load('vectorizer.pkl') # Sentiment prediction function def sentiment_prediction(text): text_arr = [text] text_transformed = vect.transform(text_arr) prediction = model.predict(text_transformed) return prediction # Main function for app layout and interaction def main(): # Set page configuration st.set_page_config(page_title="Disaster Tweet Prediction", page_icon="🎭", layout="wide") # Custom CSS styling st.markdown(""" """, unsafe_allow_html=True) # App Title st.markdown('
Disaster Tweet Prediction
', unsafe_allow_html=True) # Input area for text with st.container(): st.markdown('
', unsafe_allow_html=True) text = st.text_area("Type your tweet:", "", height=150) st.markdown('
', unsafe_allow_html=True) # Prediction button with custom style if st.button("Predict Sentiment"): if text.strip() == "": st.warning("⚠️ Please enter some text to make a prediction!") else: sentiment_pred = sentiment_prediction(text) sentiment_label = "Related with Disaster" if sentiment_pred[0] == 1 else "Not Related with Disaster" confidence = np.random.uniform(0.75, 0.95) # Fake confidence score (replace with actual if available) # Result visualization with fancy effects result_class = "Related-with-Disaster" if sentiment_pred[0] == 1 else "Not-Related-with-Disaster" st.markdown(f'
🎭 Prediction: {sentiment_label}
', unsafe_allow_html=True) st.markdown(f'
✨ Confidence: {confidence:.2f}
', unsafe_allow_html=True) if __name__ == "__main__": main()