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