bgspaditya commited on
Commit
64bfbe8
1 Parent(s): 893f89d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
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()