File size: 3,059 Bytes
771889b
 
 
 
 
 
 
 
 
 
 
 
8948a11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
title: TrustworthyAI
emoji: πŸš€
colorFrom: blue
colorTo: green
sdk: docker
sdk_version: "1.0"
app_file: backend/app.py
pinned: false
---


# TrustworthyAI

## Local Dev Env Setup

- frontend
  npm run start

- backend
  python app.py

## Setup in a new EC2 instance

Install nginx

```
sudo apt install nginx
```

Install apps

```
sudo apt install certbot python3-certbot-nginx ranger docker.io
```

Configure nginx

```
sudo certbot --nginx -d guardai.io -d www.guardai.io
```

Add this to the top of the nginx.conf on the EC2 instance

```
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s;
```

Add proxy_pass` to both 80 and 443 blocks

```
    location / {
        # Rate limits backend API calls
        limit_req zone=mylimit;

        proxy_pass http://127.0.0.1:3000/;
    }
```

See an example of final nginx configuration in`/deployment/default`.


Finally, restart nginx

```
sudo systemctl restart nginx
```



## Build and run docker

Build:

```bash
docker build --pull --rm -f Dockerfile -t trustworthy-ai .
```

To run the docker image locally:

```bash
docker run --rm -p 3000:80/tcp trustworthy-ai
```

To push docker image to the repository:

```bash
docker tag trustworthy-ai:latest paulcccccch/trustworthy-ai:latest
docker push paulcccccch/trustworthy-ai:latest
```

To pull docker:

```bash
docker login
docker run -p 3000:80 paulcccccch/trustworthy-ai:latest
```

Clean up: 

```
sudo docker stop $(sudo docker ps -aq)
sudo docker rm $(sudo docker ps -aq)
sudo docker rmi $(sudo docker images -q)
```


# Environment Setting:

## Frontend:

* a. Download "Node.js". https://nodejs.org/en/download 

* b. Once you have downloaded it successfully, run this code then you should be able to see the version number.

```bash
node --version
```

* c. Go to the 'frontend' directory and run this code and you will see a file called "node modules" in the frontend file.

```bash
npm install
```

* d. Run this code and a website should pop up.

```bash
npm run start
```

## Backend:

* a. Download "Miniconda". https://docs.conda.io/projects/miniconda/en/latest/miniconda-install.html

* b. Once you have downloaded it successfully, run this code then you should be able to see the version number.

```bash
conda --version 
```

* c. Go to the 'backend' directory.

* d. Create a virtual environment using this code: 

```bash
conda create --name 'name_of_environment'
```

* e. Activate the environment you just created using this code: 

```bash
conda activate 'name_of_environment'
```

You may check the existing environment using this code: 


```bash
conda env list
```

* f. In the environment you just activated, install all the modules in requirements.txt

```bash
pip install -r requirements.txt
```

You can use this code to check what modules you already have in your environment:

```bash
conda list
```

* g. When all the modules are successfully downloaded, you should be able to run the whole project. Run this code to see if it works. (Be sure you are in the correct environment)

```bash
python app.py
```