Spaces:
Sleeping
Sleeping
File size: 863 Bytes
23e26d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained("remomo/URLClassifier")
tokenizer = AutoTokenizer.from_pretrained("remomo/URLClassifier")
# Define prediction function
def classify_url(url):
inputs = tokenizer(url, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
pred = torch.argmax(outputs.logits, dim=1).item()
return "🔒 Safe" if pred == 0 else "⚠️ Unsafe"
# Create Gradio interface
iface = gr.Interface(fn=classify_url,
inputs=gr.Textbox(label="Enter URL"),
outputs=gr.Textbox(label="Classification"),
title="URL Safety Checker")
iface.launch(share=True)
|