Spaces:
Sleeping
Sleeping
add initial dockerfile
Browse files- app/Dockerfile +9 -0
- app/dga-classifier-service.R +36 -0
- app/launchservice.R +5 -0
app/Dockerfile
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM trestletech/plumber
|
2 |
+
MAINTAINER Carlos Catania (AKA Harpo) "[email protected]"
|
3 |
+
RUN apt install -y python-pip virtualenv
|
4 |
+
RUN R -e "install.packages('keras')"
|
5 |
+
RUN R -e "library(keras);install_keras()"
|
6 |
+
COPY . /app
|
7 |
+
WORKDIR /app
|
8 |
+
CMD ["/app/launchservice.R"]
|
9 |
+
|
app/dga-classifier-service.R
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
library(keras)
|
2 |
+
library(plumber)
|
3 |
+
|
4 |
+
# loading the DGA model for classifier
|
5 |
+
#model<-load_model_hdf5("/home/harpo/Dropbox/ongoing-work/git-repos/dga-wb-r/docker/app/pmodel.h5")
|
6 |
+
model<-load_model_hdf5("/app/asai-2019_model.h5")
|
7 |
+
modelid="cacic-2018-model"
|
8 |
+
|
9 |
+
valid_characters <- "$abcdefghijklmnopqrstuvwxyz0123456789-_."
|
10 |
+
valid_characters_vector <- strsplit(valid_characters,split="")[[1]]
|
11 |
+
tokens <- 0:length(valid_characters_vector)
|
12 |
+
names(tokens) <- valid_characters_vector
|
13 |
+
|
14 |
+
|
15 |
+
# testing function
|
16 |
+
#* @get /echo
|
17 |
+
function(msg="Hi!"){
|
18 |
+
list(msg = paste("The message is: ", msg))
|
19 |
+
}
|
20 |
+
|
21 |
+
# DGA prediction function
|
22 |
+
#* @get /predict
|
23 |
+
#* @serializer unboxedJSON
|
24 |
+
function(domain){
|
25 |
+
domain_encoded <-
|
26 |
+
|
27 |
+
sapply(
|
28 |
+
unlist(strsplit(tolower(domain),split="")), function(x) tokens [[x]]
|
29 |
+
)
|
30 |
+
|
31 |
+
# {tokens[[x]] })
|
32 |
+
domain_encoded<-pad_sequences(t(domain_encoded),maxlen=45,padding='post', truncating='post')
|
33 |
+
|
34 |
+
prediction<-predict(model,domain_encoded)
|
35 |
+
return(list(modelid=modelid,domain=domain,class=ifelse(prediction[1]>0.9,1,0),probability=prediction[1]))
|
36 |
+
}
|
app/launchservice.R
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
library(plumber)
|
2 |
+
r <- plumb("/app/dga-classifier-service.R")
|
3 |
+
#r <- plumb("/home/harpo/Dropbox/ongoing-work/git-repos/dga-wb-r/docker/app/dga-classifier-service.R")
|
4 |
+
|
5 |
+
r$run(host = "0.0.0.0",port=8002)
|