Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, set_seed
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
+
|
5 |
+
set_seed(42)
|
6 |
+
num_labels=2
|
7 |
+
id2label = {0:'benign',1:'phishing'}
|
8 |
+
label2id = {'benign':0,'phishing':1}
|
9 |
+
checkpoint = 'bgspaditya/distilbert-phish'
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint, use_fast=True, force_download=True)
|
11 |
+
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=num_labels, id2label=id2label, label2id=label2id, force_download=True)
|
12 |
+
|
13 |
+
def predict(url):
|
14 |
+
url_classifier = pipeline(task='text-classification', model=model, tokenizer=tokenizer)
|
15 |
+
result = url_classifier(url)
|
16 |
+
return {'label': result[0]['label'], 'score': result[0]['score']}
|
17 |
+
|
18 |
+
gradio_app = gr.Interface(
|
19 |
+
predict,
|
20 |
+
inputs=gr.Textbox(label="Enter URL"),
|
21 |
+
outputs=gr.Label(label="Result"),
|
22 |
+
title="Phishing URL Detection",
|
23 |
+
)
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
gradio_app.launch()
|