File size: 1,008 Bytes
07c177b
d5ccd37
07c177b
6e6a199
 
b39821e
07c177b
 
d3888b9
 
 
 
 
 
 
 
 
 
 
 
 
07c177b
 
 
 
 
 
 
 
 
 
 
d5ccd37
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
26
27
28
29
30
31
32
33
34
from transformers import pipeline
import gradio as gr

# Initialize the pipeline with TensorFlow
pipe = pipeline("text-classification", model="ZachBeesley/Spam-Detector", framework="tf")

# Function to process the input text and return the predicted label
def predict(text):
    try:
        # Use the pipeline to classify the text
        result = pipe(text)
        
        # Extract the predicted label and confidence score
        label = result[0]["label"]
        confidence = result[0]["score"]

        # Return the result
        return f"Predicted label: {label}\nConfidence: {confidence:.2f}"
    except Exception as e:
        # Handle errors
        return f"Error: {str(e)}"

# Create the Gradio interface
iface = gr.Interface(
    fn=predict,
    inputs=gr.Textbox(label="Email Text", placeholder="Paste your email text here..."),
    outputs="text",
    title="Spam Email Detector",
    description="Enter an email and find out if it's spam or not."
)

# Launch the interface
iface.launch()