Jensen-holm commited on
Commit
2c781f8
·
1 Parent(s): 0987346

initial dumb api working

Browse files
Files changed (2) hide show
  1. example/main.go +0 -72
  2. example/main.py +22 -0
example/main.go DELETED
@@ -1,72 +0,0 @@
1
- package main
2
-
3
- import (
4
- "bytes"
5
- "encoding/json"
6
- "fmt"
7
- "io/ioutil"
8
- "net/http"
9
- )
10
-
11
- type RequestPayload struct {
12
- CSVData string `json:"csv_data"`
13
- Features []string `json:"features"`
14
- Target string `json:"target"`
15
- Epochs int `json:"epochs"`
16
- LearningRate float64 `json:"learning_rate"`
17
- HiddenSize int `json:"hidden_size"`
18
- ActivationFunc string `json:"activation"`
19
- TestSize float64 `json:"test_size"`
20
- }
21
-
22
- func main() {
23
- csvBytes, err := ioutil.ReadFile("iris.csv")
24
- if err != nil {
25
- fmt.Println("Error reading CSV file: ", err)
26
- return
27
- }
28
-
29
- csvString := string(csvBytes)
30
- target := "species"
31
- features := []string{
32
- "petal length",
33
- "sepal length",
34
- "sepal width",
35
- "petal width",
36
- }
37
-
38
- payload := RequestPayload{
39
- CSVData: csvString,
40
- Features: features,
41
- Target: target,
42
- Epochs: 100,
43
- LearningRate: 0.01,
44
- HiddenSize: 12,
45
- ActivationFunc: "tanh",
46
- TestSize: 0.3,
47
- }
48
-
49
- jsonPayload, err := json.Marshal(payload)
50
- if err != nil {
51
- panic(err)
52
- }
53
-
54
- r, err := http.Post(
55
- "http://127.0.0.1:3000/neural-network",
56
- "application/json",
57
- bytes.NewBuffer(jsonPayload),
58
- )
59
- if err != nil {
60
- panic(err)
61
- }
62
-
63
- defer r.Body.Close()
64
-
65
- body, err := ioutil.ReadAll(r.Body)
66
- if err != nil {
67
- panic(err)
68
- }
69
-
70
- fmt.Println(string(body))
71
-
72
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
example/main.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ with open("iris.csv", "rb") as csv:
4
+ iris_data = csv.read()
5
+
6
+ ARGS = {
7
+ "epochs": 100,
8
+ "hidden_size": 12,
9
+ "learning_rate": 0.01,
10
+ "activation": "tanh",
11
+ "features": ["sepal width", "sepal length", "petal width", "petal length"],
12
+ "target": "species",
13
+ "data": iris_data.decode('utf-8'),
14
+ }
15
+
16
+ r = requests.post(
17
+ "http://127.0.0.1:5000/neural-network",
18
+ json=ARGS,
19
+ )
20
+
21
+ if __name__ == "__main__":
22
+ print(r.json())