Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +94 -0
- logistic_regression_model.pkl +3 -0
- requirements.txt +3 -0
- vectorizer.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load model and vectorizer
|
| 6 |
+
model = joblib.load('logistic_regression_model.pkl')
|
| 7 |
+
vect = joblib.load('vectorizer.pkl')
|
| 8 |
+
|
| 9 |
+
# Sentiment prediction function
|
| 10 |
+
def sentiment_prediction(text):
|
| 11 |
+
text_arr = [text]
|
| 12 |
+
text_transformed = vect.transform(text_arr)
|
| 13 |
+
prediction = model.predict(text_transformed)
|
| 14 |
+
return prediction
|
| 15 |
+
|
| 16 |
+
# Main function for app layout and interaction
|
| 17 |
+
def main():
|
| 18 |
+
# Set page configuration
|
| 19 |
+
st.set_page_config(page_title="Disaster Tweet Prediction", page_icon="🎭", layout="wide")
|
| 20 |
+
|
| 21 |
+
# Custom CSS styling
|
| 22 |
+
st.markdown("""
|
| 23 |
+
<style>
|
| 24 |
+
.title {
|
| 25 |
+
font-size: 36px;
|
| 26 |
+
font-weight: bold;
|
| 27 |
+
text-align: center;
|
| 28 |
+
color: #ff4c4c;
|
| 29 |
+
margin-top: 20px;
|
| 30 |
+
}
|
| 31 |
+
.input-area {
|
| 32 |
+
background-color: #f5f5f5;
|
| 33 |
+
border-radius: 10px;
|
| 34 |
+
padding: 20px;
|
| 35 |
+
margin-top: 20px;
|
| 36 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 37 |
+
}
|
| 38 |
+
.stTextArea textarea {
|
| 39 |
+
font-size: 18px;
|
| 40 |
+
border-radius: 8px;
|
| 41 |
+
padding: 12px;
|
| 42 |
+
width: 100%;
|
| 43 |
+
}
|
| 44 |
+
.result {
|
| 45 |
+
font-size: 24px;
|
| 46 |
+
font-weight: bold;
|
| 47 |
+
padding: 15px;
|
| 48 |
+
border-radius: 10px;
|
| 49 |
+
text-align: center;
|
| 50 |
+
margin-top: 20px;
|
| 51 |
+
}
|
| 52 |
+
.Related-with-Disaster {
|
| 53 |
+
background-color: #ff4c4c;
|
| 54 |
+
color: white;
|
| 55 |
+
}
|
| 56 |
+
.Not-Related-with-Disaster {
|
| 57 |
+
background-color: #4caf50;
|
| 58 |
+
color: white;
|
| 59 |
+
}
|
| 60 |
+
.confidence {
|
| 61 |
+
font-size: 20px;
|
| 62 |
+
text-align: center;
|
| 63 |
+
margin-top: 10px;
|
| 64 |
+
font-weight: 600;
|
| 65 |
+
color: #666;
|
| 66 |
+
}
|
| 67 |
+
</style>
|
| 68 |
+
""", unsafe_allow_html=True)
|
| 69 |
+
|
| 70 |
+
# App Title
|
| 71 |
+
st.markdown('<div class="title">Disaster Tweet Prediction</div>', unsafe_allow_html=True)
|
| 72 |
+
|
| 73 |
+
# Input area for text
|
| 74 |
+
with st.container():
|
| 75 |
+
st.markdown('<div class="input-area">', unsafe_allow_html=True)
|
| 76 |
+
text = st.text_area("Type your tweet:", "", height=150)
|
| 77 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 78 |
+
|
| 79 |
+
# Prediction button with custom style
|
| 80 |
+
if st.button("Predict Sentiment"):
|
| 81 |
+
if text.strip() == "":
|
| 82 |
+
st.warning("⚠️ Please enter some text to make a prediction!")
|
| 83 |
+
else:
|
| 84 |
+
sentiment_pred = sentiment_prediction(text)
|
| 85 |
+
sentiment_label = "Related with Disaster" if sentiment_pred[0] == 1 else "Not Related with Disaster"
|
| 86 |
+
confidence = np.random.uniform(0.75, 0.95) # Fake confidence score (replace with actual if available)
|
| 87 |
+
|
| 88 |
+
# Result visualization with fancy effects
|
| 89 |
+
result_class = "Related-with-Disaster" if sentiment_pred[0] == 1 else "Not-Related-with-Disaster"
|
| 90 |
+
st.markdown(f'<div class="result {result_class}">🎭 Prediction: {sentiment_label}</div>', unsafe_allow_html=True)
|
| 91 |
+
st.markdown(f'<div class="confidence">✨ Confidence: {confidence:.2f}</div>', unsafe_allow_html=True)
|
| 92 |
+
|
| 93 |
+
if __name__ == "__main__":
|
| 94 |
+
main()
|
logistic_regression_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f33621170bdadf3da702cc76496e98eaeda085a0840c1f1e850281da0fb8d23c
|
| 3 |
+
size 402239
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn
|
vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8aa54d671cda2db4a74c4e788a9fabccb107184c39a822674cb3a7f45a9be9f4
|
| 3 |
+
size 848610
|