Spaces:
Runtime error
Runtime error
Commit
·
41525d1
1
Parent(s):
3a29600
Upload 2 files
Browse files- app 2.py +30 -0
- requirements 2.txt +2 -0
app 2.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import transformers
|
| 3 |
+
from transformers import BertTokenizer, DataCollatorWithPadding
|
| 4 |
+
from transformers import AutoModelForSequenceClassification
|
| 5 |
+
tokenizer = BertTokenizer.from_pretrained('huolongguo10/check_sec')
|
| 6 |
+
model = AutoModelForSequenceClassification.from_pretrained('huolongguo10/check_sec', num_labels=2)
|
| 7 |
+
import torch
|
| 8 |
+
def check(text):
|
| 9 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 10 |
+
with torch.no_grad():
|
| 11 |
+
logits = model(**inputs).logits
|
| 12 |
+
predicted_class_id = logits.argmax().item()
|
| 13 |
+
print(f'{logits.argmax().item()}:{text}')
|
| 14 |
+
return 'secure' if predicted_class_id==0 else 'insecure'
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
text = gr.Textbox(label="Text")
|
| 17 |
+
output = gr.Textbox(label="Output Box")
|
| 18 |
+
# org = gr.Textbox(label="By normal check")
|
| 19 |
+
greet_btn = gr.Button("Check!")
|
| 20 |
+
greet_btn.click(fn=check, inputs=text, outputs=output, api_name="check")
|
| 21 |
+
gr.Markdown('''# check_sec
|
| 22 |
+
检查web参数安全性,目前只支持xss
|
| 23 |
+
## 类型
|
| 24 |
+
```
|
| 25 |
+
LABEL_0: secure
|
| 26 |
+
LABEL_1: insecure(可能包含xss payload)
|
| 27 |
+
```
|
| 28 |
+
''')
|
| 29 |
+
# gr.Interface.load("models/huolongguo10/check_sec").launch()
|
| 30 |
+
demo.launch()
|
requirements 2.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|