|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
|
|
|
|
model_name = "vsk21/spam_or_ham_bert-base-uncased" |
|
model = AutoModelForSequenceClassification.from_pretrained(model_name) |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
|
|
|
def classify_email(text): |
|
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True) |
|
outputs = model(**inputs) |
|
predictions = outputs.logits.argmax(axis=-1).item() |
|
return "Spam" if predictions == 1 else "Ham" |
|
|
|
|
|
interface = gr.Interface(fn=classify_email, |
|
inputs="text", |
|
outputs="text", |
|
title="Email Classification", |
|
description="Enter an email message to classify it as Spam or Ham.") |
|
|
|
|
|
interface.launch() |
|
|