File size: 948 Bytes
b738a54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()