Commit
·
7597dd3
1
Parent(s):
f384ae1
Update app.py
Browse files
app.py
CHANGED
@@ -5,13 +5,20 @@ 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
|
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")
|
|
|
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_each(text):
|
9 |
+
inputs = tokenizer(text, return_tensors="pt",max_length=512)
|
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 |
+
def check(text):
|
16 |
+
t=text
|
17 |
+
while len(t)>512:
|
18 |
+
t=t[0:511]
|
19 |
+
if check_each(t)=='insecure':
|
20 |
+
return 'insecure'
|
21 |
+
return check_each(t)
|
22 |
with gr.Blocks() as demo:
|
23 |
text = gr.Textbox(label="Text")
|
24 |
output = gr.Textbox(label="Output Box")
|