Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
|
| 4 |
+
# Load the trained model and vectorizer
|
| 5 |
+
model = pickle.load(open('spam_model.pkl', 'rb'))
|
| 6 |
+
vectorizer = pickle.load(open('vectorizer.pkl', 'rb'))
|
| 7 |
+
|
| 8 |
+
def predict_sms(message):
|
| 9 |
+
transformed_text = vectorizer.transform([message])
|
| 10 |
+
prediction = model.predict(transformed_text)[0]
|
| 11 |
+
return "Spam" if prediction == 1 else "Not Spam"
|
| 12 |
+
|
| 13 |
+
# Gradio Web Interface
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=predict_sms,
|
| 16 |
+
inputs=gr.Textbox(label="Enter SMS Message"),
|
| 17 |
+
outputs=gr.Label(),
|
| 18 |
+
title="SMS Spam Classifier",
|
| 19 |
+
description="Enter a message to check if it's spam or not."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch the app
|
| 23 |
+
iface.launch()
|