huolongguo10 commited on
Commit
2c956a9
1 Parent(s): 86a4a69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -9
app.py CHANGED
@@ -1,10 +1,26 @@
1
  import gradio as gr
2
- gr.Markdown('''# check_sec
3
- 检查web参数安全性,目前只支持xss
4
- ## 类型
5
- ```
6
- LABEL_0: secure
7
- LABEL_1: insecure(可能包含xss payload)
8
- ```
9
- ''')
10
- gr.Interface.load("models/huolongguo10/check_sec").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import transformers
3
+ tokenizer = BertTokenizer.from_pretrained('huolongguo10/check_sec')
4
+ model = AutoModelForSequenceClassification.from_pretrained('huolongguo10/check_sec', num_labels=2)
5
+ import torch
6
+ def check(text):
7
+ with torch.no_grad():
8
+ logits = model(**inputs).logits
9
+ predicted_class_id = logits.argmax().item()
10
+ return 'secure' if predicted_class_id==0 else 'insecure'
11
+ with gr.Blocks() as demo:
12
+ text = gr.Textbox(label="Text")
13
+ output = gr.Textbox(label="Output Box")
14
+ org = gr.Textbox(label="By normal check")
15
+ greet_btn = gr.Button("Check!")
16
+ greet_btn.click(fn=check, inputs=text, outputs=output, api_name="check")
17
+ gr.Markdown('''# check_sec
18
+ 检查web参数安全性,目前只支持xss
19
+ ## 类型
20
+ ```
21
+ LABEL_0: secure
22
+ LABEL_1: insecure(可能包含xss payload)
23
+ ```
24
+ ''')
25
+ # gr.Interface.load("models/huolongguo10/check_sec").launch()
26
+ demo.launch()