Spaces:
Sleeping
Sleeping
| 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 🦄") | |