noobpk commited on
Commit
9ca05ed
·
verified ·
1 Parent(s): 8505a08

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # python 3.9
2
+ # Available backend options are: "jax", "torch", "tensorflow".
3
+ import os
4
+ os.environ["KERAS_BACKEND"] = "tensorflow"
5
+
6
+ from tensorflow.keras.models import load_model
7
+ from sentence_transformers import SentenceTransformer
8
+ from huggingface_hub import hf_hub_download
9
+
10
+
11
+ def load_modeler():
12
+ local_model_path = hf_hub_download(
13
+ repo_id="noobpk/web-attack-detection",
14
+ filename="model.h5"
15
+ )
16
+ return load_model(local_model_path)
17
+
18
+ model = load_modeler()
19
+
20
+ def load_encoder():
21
+ model_name_or_path = os.environ.get("model_name_or_path", "sentence-transformers/all-MiniLM-L6-v2")
22
+ return SentenceTransformer(model_name_or_path)
23
+
24
+ encoder = load_encoder()
25
+
26
+ if __name__ == "__main__":
27
+ payload = input("Enter payload: ")
28
+ print("Processing...")
29
+
30
+ embeddings = encoder.encode(payload).reshape((1, 384))
31
+ prediction = model.predict(embeddings)
32
+ accuracy = float(prediction[0][0] * 100)
33
+ print(f"Accuracy: {accuracy}")