import subprocess # Install NLTK and download required data subprocess.run(["pip", "install", "nltk"]) subprocess.run(["pip", "install", "scikit-learn"]) import nltk nltk.download('punkt') nltk.download('stopwords') import gradio as gr import pickle import nltk import string from nltk.corpus import stopwords from nltk.stem.porter import PorterStemmer # Load pre-trained model and vectorizer ps = PorterStemmer() tf = pickle.load(open('vectorizerr.pkl', 'rb')) model = pickle.load(open('modell.pkl', 'rb')) def transform_text(text): text = text.lower() text = nltk.word_tokenize(text) y = [] for i in text: if i.isalnum(): y.append(i) text = y[:] y.clear() for i in text: if i not in stopwords.words('english') and i not in string.punctuation: y.append(i) text = y[:] y.clear() for i in text: y.append(ps.stem(i)) return " ".join(y) def predict_spam(input_sms): transform_sms = transform_text(input_sms) vector_input = tf.transform([transform_sms]) result = model.predict(vector_input)[0] if result == 1: return 'Alert! This message is likely spam.' else: return 'This message is safe and not spam!' # Gradio interface input_text = gr.Textbox(lines=5, label="Enter the message") output_text = gr.Textbox(label="Prediction") gr.Interface(fn=predict_spam, inputs=input_text, outputs=output_text, title="SMS Spam Classifier", description="Enter a message below to check if it's spam or not.").launch()