File size: 880 Bytes
d1b331f
 
d43925d
d1b331f
d43925d
 
 
 
 
 
d1b331f
 
d43925d
 
 
 
 
 
d1b331f
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pickle
import sklearn  # Ensure sklearn is imported

# Load the trained model and vectorizer safely
try:
    model = pickle.load(open('model.pkl', 'rb'))  # Changed filename
    vectorizer = pickle.load(open('vectorizer.pkl', 'rb'))  # Keep this as it is
except Exception as e:
    print(f"Error loading model: {e}")

def predict_sms(message):
    try:
        transformed_text = vectorizer.transform([message])
        prediction = model.predict(transformed_text)[0]
        return "Spam" if prediction == 1 else "Not Spam"
    except Exception as e:
        return f"Error: {e}"

# Gradio Web Interface
iface = gr.Interface(
    fn=predict_sms,
    inputs=gr.Textbox(label="Enter SMS Message"),
    outputs=gr.Label(),
    title="SMS Spam Classifier",
    description="Enter a message to check if it's spam or not."
)

# Launch the app
iface.launch()