ibrahim yıldız commited on
Commit
0dfcb6a
·
verified ·
1 Parent(s): 9b010ab

Upload 2 files

Browse files
Files changed (2) hide show
  1. NLP_model.pkl +3 -0
  2. app.py +51 -0
NLP_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:94581e03b8a93788ab8df45d21834621b95437b20725aab66b0938b88ed02623
3
+ size 616345
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import re
4
+ import nltk
5
+ from nltk.corpus import stopwords
6
+ from nltk.stem import PorterStemmer
7
+ #from sklearn.feature_extraction.text import CountVectorizer
8
+ #from sklearn.naive_bayes import BernoulliNB
9
+
10
+ # Load the saved model and vectorizer
11
+ with open("NLP_model.pkl", "rb") as file:
12
+ model, vect = pickle.load(file)
13
+
14
+ # Define a function to preprocess the user input
15
+ def preprocess_text(text):
16
+ text = re.sub(r'<.*?>', '', text)
17
+ text = re.sub(r'http\S+', '', text)
18
+ text = re.sub(r'[^a-zA-Z\s]', '', text)
19
+ text = text.lower()
20
+ tokens = nltk.word_tokenize(text)
21
+ stop_words = set(stopwords.words('english'))
22
+ tokens = [word for word in tokens if word not in stop_words]
23
+ stemmer = PorterStemmer()
24
+ tokens = [stemmer.stem(word) for word in tokens]
25
+ preprocessed_text = ' '.join(tokens)
26
+ return preprocessed_text
27
+
28
+
29
+ st.title("Emergency Tweet Classifier 🐦")
30
+ st.image("https://img.gta5-mods.com/q95/images/emergency-utility-truck/b30de4-Station%2032.jpg")
31
+ st.write("This NLP model has 79% accuracy. Enter a tweet to determine if there is an emergency or not.")
32
+
33
+ # User input text box with smaller height
34
+ user_input = st.text_area("Write Tweet Here:", value="13,000 people receive evacuation.")
35
+
36
+ # Button to classify text
37
+ if st.button("Classify"):
38
+ # Preprocess the user input
39
+ processed_input = preprocess_text(user_input)
40
+
41
+ # Vectorize the processed input using the loaded vectorizer
42
+ processed_input_vectorized = vect.transform([processed_input])
43
+
44
+ # Predict using the loaded model
45
+ prediction = model.predict(processed_input_vectorized)
46
+
47
+ # Display result
48
+ if prediction[0] == 1:
49
+ st.title("There is an emergency 🚨")
50
+ else:
51
+ st.title("There is NO emergency 🦄")