Spaces:
Runtime error
Runtime error
ankush-003
commited on
Commit
•
92fdd7f
1
Parent(s):
f875dc5
Update app.py
Browse files
app.py
CHANGED
@@ -5,11 +5,15 @@ import tensorflow as tf
|
|
5 |
# from transformers import TFAutoModelForSequenceClassification
|
6 |
|
7 |
# Load model directly
|
8 |
-
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
|
9 |
|
10 |
-
# tokenizer = AutoTokenizer.from_pretrained("ankush-003/nosqli_identifier")
|
11 |
-
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
12 |
-
model = TFAutoModelForSequenceClassification.from_pretrained("ankush-003/nosqli_identifier")
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def predict(username, pwd, label, payload_text = None):
|
15 |
if(payload_text is None or payload_text is ""):
|
@@ -18,13 +22,14 @@ def predict(username, pwd, label, payload_text = None):
|
|
18 |
"password": pwd
|
19 |
}
|
20 |
payload_text = json.dumps(payload)
|
21 |
-
inputs = tokenizer(payload_text, return_tensors="tf")
|
22 |
# model = TFAutoModelForSequenceClassification.from_pretrained("ankush-003/nosqli_identifier")
|
23 |
-
logits = model(**inputs).logits
|
24 |
-
predicted_class_id = int(tf.math.argmax(logits, axis=-1)[0])
|
25 |
# print(model.config.id2label[predicted_class_id])
|
|
|
26 |
|
27 |
-
return payload_text,
|
28 |
|
29 |
input_elements = [gr.Textbox(label="Enter Username"), gr.Textbox(label="Enter Password"), gr.Dropdown(["Malitious", "Benign"], label="Expected", info="Enter expected value"),
|
30 |
gr.Textbox(label="Enter Payload", info="Optional if username and password entered already")]
|
@@ -34,7 +39,7 @@ demo = gr.Interface(
|
|
34 |
description="DistilBERT-based NoSQL Injection Payload Detection Model ",
|
35 |
fn=predict,
|
36 |
inputs=input_elements,
|
37 |
-
outputs=[gr.Textbox(label="Generated Payload"), gr.Textbox(label="Model Prediction")]
|
38 |
)
|
39 |
demo.launch(debug=True)
|
40 |
# gr.Interface.load("models/ankush-003/nosqli_identifier").launch()
|
|
|
5 |
# from transformers import TFAutoModelForSequenceClassification
|
6 |
|
7 |
# Load model directly
|
8 |
+
# from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
|
9 |
|
10 |
+
# # tokenizer = AutoTokenizer.from_pretrained("ankush-003/nosqli_identifier")
|
11 |
+
# tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
12 |
+
# model = TFAutoModelForSequenceClassification.from_pretrained("ankush-003/nosqli_identifier")
|
13 |
+
from transformers import pipeline
|
14 |
+
|
15 |
+
classifier = pipeline("sentiment-analysis", model="ankush-003/nosqli_identifier")
|
16 |
+
# classifier(payload)
|
17 |
|
18 |
def predict(username, pwd, label, payload_text = None):
|
19 |
if(payload_text is None or payload_text is ""):
|
|
|
22 |
"password": pwd
|
23 |
}
|
24 |
payload_text = json.dumps(payload)
|
25 |
+
# inputs = tokenizer(payload_text, return_tensors="tf")
|
26 |
# model = TFAutoModelForSequenceClassification.from_pretrained("ankush-003/nosqli_identifier")
|
27 |
+
# logits = model(**inputs).logits
|
28 |
+
# predicted_class_id = int(tf.math.argmax(logits, axis=-1)[0])
|
29 |
# print(model.config.id2label[predicted_class_id])
|
30 |
+
prediction = classifier(payload_text)
|
31 |
|
32 |
+
return payload_text, prediction['label'], prediction['score'] * 100
|
33 |
|
34 |
input_elements = [gr.Textbox(label="Enter Username"), gr.Textbox(label="Enter Password"), gr.Dropdown(["Malitious", "Benign"], label="Expected", info="Enter expected value"),
|
35 |
gr.Textbox(label="Enter Payload", info="Optional if username and password entered already")]
|
|
|
39 |
description="DistilBERT-based NoSQL Injection Payload Detection Model ",
|
40 |
fn=predict,
|
41 |
inputs=input_elements,
|
42 |
+
outputs=[gr.Textbox(label="Generated Payload"), gr.Textbox(label="Model Prediction"), gr.Slider(0, 100, label="Score")]
|
43 |
)
|
44 |
demo.launch(debug=True)
|
45 |
# gr.Interface.load("models/ankush-003/nosqli_identifier").launch()
|