Muhammad-Arham's picture
Update app.py
2c8bd9e verified
raw
history blame
940 Bytes
import gradio as gr
import pickle
import sklearn # Ensure scikit-learn is available
# Load the trained model and vectorizer safely
try:
model = pickle.load(open('model.pkl', 'rb')) # Ensure correct file name
vectorizer = pickle.load(open('vectorizer.pkl', 'rb'))
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."
)
# Ensure Hugging Face properly serves the app
iface.launch(server_name="0.0.0.0", server_port=7860)