Ifeanyi commited on
Commit
e77f270
·
verified ·
1 Parent(s): a3f504c

Upload 5 files

Browse files
Files changed (5) hide show
  1. API.R +37 -0
  2. Dockerfile +30 -0
  3. Server.R +4 -0
  4. dockerignore.txt +9 -0
  5. lm_model +0 -0
API.R ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(plumber)
2
+
3
+ #* @apiTitle Cars Model App
4
+
5
+ #* @param cyl number of cylinders,
6
+ #* @param disp displacement
7
+ #* @param hp horse-power
8
+ #* @param drat drat
9
+ #* @param wt weight
10
+ #* @param qsec qsec
11
+ #* @param vs vs
12
+ #* @param am am
13
+ #* @param gear number of gear level
14
+ #* @param carb carbonmono-oxide emission
15
+ #* @post /predict
16
+ function(cyl,disp,hp,drat,wt,qsec,vs,am,gear,carb){
17
+
18
+ new_data <- data.frame(
19
+ cyl = as.numeric(cyl),
20
+ disp = as.numeric(disp),
21
+ hp = as.numeric(hp),
22
+ drat = as.numeric(drat),
23
+ wt = as.numeric(wt),
24
+ qsec = as.numeric(qsec),
25
+ vs = as.numeric(vs),
26
+ am = as.numeric(am),
27
+ gear = as.numeric(gear),
28
+ carb = as.numeric(carb)
29
+ )
30
+
31
+ model <- readRDS("lm_model")
32
+
33
+ response = predict(model,new_data)
34
+
35
+ return(response)
36
+
37
+ }
Dockerfile ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official R image as the base image
2
+ FROM rocker/r-base:4.3.0
3
+
4
+ # Install system dependencies including libsodium
5
+ RUN apt-get update && apt-get install -y \
6
+ libcurl4-openssl-dev \
7
+ libssl-dev \
8
+ libxml2-dev \
9
+ libgit2-dev \
10
+ libsodium-dev \
11
+ && apt-get clean \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Install plumber dependencies manually
15
+ RUN R -e "install.packages(c('stringi', 'jsonlite', 'webutils', 'httpuv', 'promises'), repos='https://cloud.r-project.org/')"
16
+
17
+ # Install plumber package
18
+ RUN R -e "install.packages('plumber', repos='https://cloud.r-project.org/')"
19
+
20
+ # Set the working directory
21
+ WORKDIR /app
22
+
23
+ # Copy the API and Server scripts into the container
24
+ COPY . /app
25
+
26
+ # Expose the port that the API will run on
27
+ EXPOSE 8080
28
+
29
+ # CMD to run the Server script
30
+ CMD ["Rscript", "Server.R"]
Server.R ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ library(plumber)
2
+
3
+ pr("API.R") |>
4
+ pr_run(host = "0.0.0.0",port = 8080)
dockerignore.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ .Rproj.user
2
+ .Rhistory
3
+ .RData
4
+ .Ruserdata
5
+ *.Rproj
6
+ .git
7
+ .gitignore
8
+ *.log
9
+ data/raw
lm_model ADDED
Binary file (5.35 kB). View file