Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import pandas as pd | |
# Load dataset | |
DATASET_PATH = "spam.csv" | |
df = pd.read_csv(DATASET_PATH, encoding="latin1") | |
# Load a spam classification model | |
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection") | |
def spam_detector(text): | |
result = classifier(text) | |
return "Spam" if result[0]['label'].lower() == "Spam" else "Not Spam" | |
# Create Gradio UI | |
app = gr.Interface( | |
fn=spam_detector, | |
inputs=gr.Textbox(label="Enter a message"), | |
outputs=gr.Textbox(label="Prediction"), | |
title="Spam Detector", | |
description="Enter a message to check if it's spam or not." | |
) | |
# Run the app | |
if __name__ == "__main__": | |
print("Loaded dataset preview:") | |
print(df.head()) | |
app.launch() | |