joaocansi
commited on
Commit
·
ab2a4bd
1
Parent(s):
83974f2
fix: return number instead of text
Browse files- X_test.npy +0 -3
- app.py +3 -6
- requirements.txt +1 -1
X_test.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:e33b145f1d8644611b497666ffaac86b3bed0b928dcf9fd8ab7e06216c754591
|
3 |
-
size 3840128
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -14,16 +14,13 @@ data = np.load("X_test.npy")
|
|
14 |
iso_forest = IsolationForest(contamination=0.1, random_state=42)
|
15 |
iso_forest.fit(data)
|
16 |
|
17 |
-
def
|
18 |
with torch.no_grad():
|
19 |
inputs = tokenizer(text, return_tensors='pt', truncation=True, padding=True, max_length=256)
|
20 |
outputs = model(**inputs)
|
21 |
cls_embedding = outputs.last_hidden_state[:, 0, :].cpu().numpy()
|
22 |
pred = iso_forest.predict(cls_embedding)[0]
|
23 |
-
|
24 |
-
return "Anomaly detected"
|
25 |
-
else:
|
26 |
-
return "Normal"
|
27 |
|
28 |
-
demo = gr.Interface(fn=
|
29 |
demo.launch()
|
|
|
14 |
iso_forest = IsolationForest(contamination=0.1, random_state=42)
|
15 |
iso_forest.fit(data)
|
16 |
|
17 |
+
def classify_email(text):
|
18 |
with torch.no_grad():
|
19 |
inputs = tokenizer(text, return_tensors='pt', truncation=True, padding=True, max_length=256)
|
20 |
outputs = model(**inputs)
|
21 |
cls_embedding = outputs.last_hidden_state[:, 0, :].cpu().numpy()
|
22 |
pred = iso_forest.predict(cls_embedding)[0]
|
23 |
+
return pred
|
|
|
|
|
|
|
24 |
|
25 |
+
demo = gr.Interface(fn=classify_email, inputs="text", outputs="number")
|
26 |
demo.launch()
|
requirements.txt
CHANGED
@@ -3,4 +3,4 @@ scikit-learn
|
|
3 |
tqdm
|
4 |
torch
|
5 |
gradio
|
6 |
-
numpy
|
|
|
3 |
tqdm
|
4 |
torch
|
5 |
gradio
|
6 |
+
numpy
|