import gradio as gr import re import joblib p_spam = joblib.load("p_spam.pkl") p_non_spam = joblib.load("p_non_spam.pkl") parameters_spam = joblib.load("parameters_spam.pkl") parameters_non_spam = joblib.load("parameters_non_spam.pkl") def classify(message): message = re.sub("\W", " ", message) message = message.lower().split() p_spam_given_message = p_spam p_non_spam_given_message = p_non_spam for word in message: if word in parameters_spam: p_spam_given_message *= parameters_spam[word] if word in parameters_non_spam: p_non_spam_given_message *= parameters_non_spam[word] if p_spam_given_message > p_non_spam_given_message: return "Spam" elif p_non_spam_given_message > p_spam_given_message: return "Non-Spam" else: return "Equal probabilities, human needed to classify this!" ir = gr.Interface(classify,inputs="text",outputs="text") ir.launch()