Spaces:
Build error
Build error
Commit
·
fae8f77
1
Parent(s):
eec3b88
updated example for new format
Browse files- example/main.go +21 -19
- server.go +1 -1
example/main.go
CHANGED
|
@@ -9,37 +9,39 @@ import (
|
|
| 9 |
)
|
| 10 |
|
| 11 |
type RequestPayload struct {
|
| 12 |
-
CSVData
|
| 13 |
-
Features
|
| 14 |
-
Target
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
|
| 19 |
func main() {
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
csvBytes, err := ioutil.ReadFile(filePath)
|
| 23 |
if err != nil {
|
| 24 |
fmt.Println("Error reading CSV file: ", err)
|
| 25 |
return
|
| 26 |
}
|
| 27 |
|
| 28 |
csvString := string(csvBytes)
|
| 29 |
-
features := []string{"petal length", "sepal length", "sepal width", "petal width"}
|
| 30 |
target := "species"
|
| 31 |
-
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
}
|
| 37 |
|
| 38 |
payload := RequestPayload{
|
| 39 |
-
CSVData:
|
| 40 |
-
Features:
|
| 41 |
-
Target:
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
jsonPayload, err := json.Marshal(payload)
|
|
@@ -48,7 +50,7 @@ func main() {
|
|
| 48 |
}
|
| 49 |
|
| 50 |
r, err := http.Post(
|
| 51 |
-
"http://127.0.0.1:3000/",
|
| 52 |
"application/json",
|
| 53 |
bytes.NewBuffer(jsonPayload),
|
| 54 |
)
|
|
|
|
| 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 |
}
|
| 20 |
|
| 21 |
func main() {
|
| 22 |
+
csvBytes, err := ioutil.ReadFile("iris.csv")
|
|
|
|
|
|
|
| 23 |
if err != nil {
|
| 24 |
fmt.Println("Error reading CSV file: ", err)
|
| 25 |
return
|
| 26 |
}
|
| 27 |
|
| 28 |
csvString := string(csvBytes)
|
|
|
|
| 29 |
target := "species"
|
| 30 |
+
features := []string{
|
| 31 |
+
"petal length",
|
| 32 |
+
"sepal length",
|
| 33 |
+
"sepal width",
|
| 34 |
+
"petal width",
|
| 35 |
}
|
| 36 |
|
| 37 |
payload := RequestPayload{
|
| 38 |
+
CSVData: csvString,
|
| 39 |
+
Features: features,
|
| 40 |
+
Target: target,
|
| 41 |
+
Epochs: 100,
|
| 42 |
+
LearningRate: 0.01,
|
| 43 |
+
HiddenSize: 12,
|
| 44 |
+
ActivationFunc: "tanh",
|
| 45 |
}
|
| 46 |
|
| 47 |
jsonPayload, err := json.Marshal(payload)
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
r, err := http.Post(
|
| 53 |
+
"http://127.0.0.1:3000/neural-network",
|
| 54 |
"application/json",
|
| 55 |
bytes.NewBuffer(jsonPayload),
|
| 56 |
)
|
server.go
CHANGED
|
@@ -12,7 +12,7 @@ func main() {
|
|
| 12 |
// that we will be able to validate.
|
| 13 |
app.Post("/neural-network", func(c *fiber.Ctx) error {
|
| 14 |
|
| 15 |
-
|
| 16 |
if err != nil {
|
| 17 |
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
| 18 |
"error": err,
|
|
|
|
| 12 |
// that we will be able to validate.
|
| 13 |
app.Post("/neural-network", func(c *fiber.Ctx) error {
|
| 14 |
|
| 15 |
+
_, err := nn.NewNN(c)
|
| 16 |
if err != nil {
|
| 17 |
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
| 18 |
"error": err,
|