File size: 1,840 Bytes
0dfcb6a
 
 
d7b146b
0dfcb6a
 
ffec371
ebd2665
91258e8
 
0dfcb6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import streamlit as st
import re
import nltk
import pickle
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer
nltk.download('punkt')
nltk.download('stopwords')
#from sklearn.feature_extraction.text import CountVectorizer
#from sklearn.naive_bayes import BernoulliNB

# Load the saved model and vectorizer
with open("NLP_model.pkl", "rb") as file:
    model, vect = pickle.load(file)

# Define a function to preprocess the user input
def preprocess_text(text):
    text = re.sub(r'<.*?>', '', text)
    text = re.sub(r'http\S+', '', text)
    text = re.sub(r'[^a-zA-Z\s]', '', text)
    text = text.lower()
    tokens = nltk.word_tokenize(text)
    stop_words = set(stopwords.words('english'))
    tokens = [word for word in tokens if word not in stop_words]
    stemmer = PorterStemmer()
    tokens = [stemmer.stem(word) for word in tokens]
    preprocessed_text = ' '.join(tokens)
    return preprocessed_text


st.title("Emergency Tweet Classifier 🐦")
st.image("https://img.gta5-mods.com/q95/images/emergency-utility-truck/b30de4-Station%2032.jpg")
st.write("This NLP model has 79% accuracy. Enter a tweet to determine if there is an emergency or not.")

# User input text box with smaller height
user_input = st.text_area("Write Tweet Here:", value="13,000 people receive evacuation.")

# Button to classify text
if st.button("Classify"):
    # Preprocess the user input
    processed_input = preprocess_text(user_input)
    
    # Vectorize the processed input using the loaded vectorizer
    processed_input_vectorized = vect.transform([processed_input])
    
    # Predict using the loaded model
    prediction = model.predict(processed_input_vectorized)
    
    # Display result
    if prediction[0] == 1:
        st.title("There is an emergency 🚨")
    else:
        st.title("There is NO emergency 🦄")