Spaces:
Sleeping
Sleeping
Download app.py from Learnix-AI-Lab/sms-spam-detector: direct link, hf CLI and curl.
- Browser
- Download file 671 Bytes
-
https://huggingface.co/spaces/Learnix-AI-Lab/sms-spam-detector/resolve/main/app.py
- Command line
-
hf download hf://spaces/Learnix-AI-Lab/sms-spam-detector/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Learnix-AI-Lab/sms-spam-detector/resolve/main/app.py
671 Bytes
| import gradio as gr | |
| import joblib | |
| # Load model and vectorizer | |
| model = joblib.load('model.joblib') | |
| vectorizer = joblib.load('vectorizer.joblib') | |
| def predict(message): | |
| tfidf = vectorizer.transform([message]) | |
| pred = model.predict(tfidf)[0] | |
| probs = model.predict_proba(tfidf)[0] | |
| label = 'SPAM' if pred == 1 else 'HAM' | |
| conf = probs[1] if pred == 1 else probs[0] | |
| return f'{label} ({conf:.2%})' | |
| interface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(lines=2, placeholder='Enter text here...'), | |
| outputs='text', | |
| title='SMS Spam Detector', | |
| description='A Multinomial Naive Bayes model for SMS spam detection.' | |
| ) | |
| interface.launch() | |