Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
# Load the pipeline from your Hugging Face model
|
4 |
+
pipe = pipeline("text-classification", model="ZachBeesley/Spam-Detector")
|
5 |
+
|
6 |
+
# Function to process the input text and return the predicted label
|
7 |
+
def predict(text):
|
8 |
+
# Use the pipeline to classify the text
|
9 |
+
result = pipe(text)
|
10 |
+
|
11 |
+
# Extract the predicted label and confidence score
|
12 |
+
label = result[0]["label"]
|
13 |
+
confidence = result[0]["score"]
|
14 |
+
|
15 |
+
# Return the result
|
16 |
+
return f"Predicted label: {label}\nConfidence: {confidence:.2f}"
|
17 |
+
|
18 |
+
# Create the Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=predict,
|
21 |
+
inputs=gr.Textbox(label="Email Text", placeholder="Paste your email text here..."),
|
22 |
+
outputs="text",
|
23 |
+
title="Spam Email Detector",
|
24 |
+
description="Enter an email and find out if it's spam or not."
|
25 |
+
)
|
26 |
+
|
27 |
+
# Launch the interface
|
28 |
+
iface.launch()
|