forked from MindExMachina/smartgeometry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
55 lines (49 loc) · 1.02 KB
/
util.go
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
package main
import (
"fmt"
"net"
"os"
"os/exec"
)
// Env retrieves an environment variable from the .env file
func Env(s string) string {
value := os.Getenv(s)
if value == "" {
log.WithField(s, value).Fatal("$" + s + " must be set")
}
return value
}
// Get retrieves your network ip (e.g., 10.0.0.200 instead of 127.0.0.1)
func Get() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
fmt.Println("Oops: " + err.Error() + "\n")
os.Exit(1)
return ""
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
return ""
}
// Pix2pixGenerate generates an output image using a pix2pix model.
func Pix2pixGenerate(modelDir, inputFile, outputFile string) {
cmd := exec.Command(
"python2",
Env("PIX2PIX_PROCESSLOCALPY"),
"--model_dir",
modelDir,
"--input_file",
inputFile,
"--output_file",
outputFile,
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
// log.Println(cmd.Run())
}