File size: 628 Bytes
a3e307c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import tensorflow as tf
import gradio as gr


model = tf.keras.models.load_model('model')

def predict_spam(message):
    pred_prob = model.predict([message])[0][0]
    label = "Spam" if pred_prob > 0.5 else "Ham"
    confidence = f"{pred_prob * 100:.2f}%" if label == "Spam" else f"{(1 - pred_prob) * 100:.2f}%"
    return f"{label} ({confidence})"


iface = gr.Interface(
    fn=predict_spam, 
    inputs="text", 
    outputs="text",
    title="Ham or Spam Classifier",
    description="A Ham or Spam Classifier created using TensorFlow. Input a message to see if it's classified as Ham or Spam!",
)

iface.launch(share=True)