Spaces:
Runtime error
Runtime error
File size: 1,954 Bytes
b54e71a 93e018c 5fa11d7 309d442 e385089 309d442 92fdd7f 309d442 92fdd7f bb27896 0e7f3ec a8afce4 b2d6b51 93e018c 92fdd7f 309d442 92fdd7f 6ef3ddb 42d51db 4684a0e b54e71a 915d3e0 282d4bf 269fec5 6ef3ddb f875dc5 a87481b 6ef3ddb 269fec5 e646e66 6ef3ddb 93b0079 6ef3ddb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import json
import tensorflow as tf
# from transformers import AutoTokenizer
# from transformers import TFAutoModelForSequenceClassification
# Load model directly
# from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
# # tokenizer = AutoTokenizer.from_pretrained("ankush-003/nosqli_identifier")
# tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
# model = TFAutoModelForSequenceClassification.from_pretrained("ankush-003/nosqli_identifier")
from transformers import pipeline
classifier = pipeline("sentiment-analysis", model="ankush-003/nosqli_identifier")
# classifier(payload)
def predict(username, pwd, label, payload_text = None):
if(payload_text is None or payload_text is ""):
payload = {
"username": username,
"password": pwd
}
payload_text = json.dumps(payload)
# inputs = tokenizer(payload_text, return_tensors="tf")
# model = TFAutoModelForSequenceClassification.from_pretrained("ankush-003/nosqli_identifier")
# logits = model(**inputs).logits
# predicted_class_id = int(tf.math.argmax(logits, axis=-1)[0])
# print(model.config.id2label[predicted_class_id])
prediction = classifier(payload_text)[0]
return payload_text, {prediction["label"]: prediction["score"]}
input_elements = [gr.Textbox(label="Enter Username"), gr.Textbox(label="Enter Password"), gr.Dropdown(["Malicious", "Benign"], label="Expected", info="Enter expected value"),
gr.Textbox(label="Enter Payload", info="Optional if username and password entered already")]
demo = gr.Interface(
title="NoSQLi Detector",
description="DistilBERT-based NoSQL Injection Payload Detection Model",
fn=predict,
inputs=input_elements,
outputs=[gr.Textbox(label="Generated Payload"), gr.Label(label="Scores")]
)
demo.launch(debug=True)
# gr.Interface.load("models/ankush-003/nosqli_identifier").launch() |