-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAPI.jl
More file actions
59 lines (51 loc) · 1.33 KB
/
API.jl
File metadata and controls
59 lines (51 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module API
using Genie
using Genie.Renderers.Json: json
using Flux, DataFrames, JLD2, DelimitedFiles
using SwagUI, SwaggerMarkdown
const data = readdlm("data/HousingData_normalized.dlf", ',')
model = JLD2.load("models/bostonflux.jld2", "model")
function predict()
house = data[params(:id), 1:13]
@show house
json("MEDV" => model(house))
end
@swagger """
/api/predict/{id}:
get:
description: Predict the MEDV of a house.
parameters:
- in: path
name: id
required: true
description: Numeric ID of the house to get the prediction.
schema:
type: integer
responses:
'200':
description: OK
"""
route("/api/predict/:id::Int", predict, method=GET)
@swagger """
/api/reload:
get:
description: Reload the neural network model.
responses:
'200':
description: OK
"""
route("/api/reload") do
model = JLD2.load("models/bostonflux.jld2", "model")
"Model reloaded"
end
info = Dict{String,Any}()
info["title"] = "Boston housing MEDV prediction"
info["version"] = "1.0.5"
optional_fields = Dict{String,Any}()
if haskey(ENV, "BASEPATH")
optional_fields["servers"] = [Dict("url" => ENV["BASEPATH"])]
end
openApi = OpenAPI("3.0", info, optional_fields=optional_fields)
swagger_document = build(openApi)
ui() = render_swagger(swagger_document)
end