You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The optimal approach to developing Web-Apps or Micro-Services using Synalinks involves building REST APIs and deploying them. You can deploy these APIs locally to test your system or on a cloud provider of your choice to scale to millions of users.
3
+
The optimal approach to developing web-apps or micro-services using Synalinks involves building REST APIs and deploying them. You can deploy these APIs locally to test your system or on a cloud provider of your choice to scale to millions of users.
4
4
5
5
For this purpose, you will need to use FastAPI, a Python library that makes it easy and straightforward to create REST APIs. If you use the default backend, the DataModel will be compatible with FastAPI as their both use Pydantic.
6
6
7
-
First, let's see how a production-ready project is structured.
7
+
In this tutorial we are going to make a backend that run locally to test our system.
8
8
9
-
In this tutorial, we will focus only on the backend of your application.
9
+
## Project structure
10
10
11
-
For the purpose of this tutorial, we will skip authentification. But because is is higly dependent on your business usecase/frontend, we will not handle it here.
11
+
Your project structure should look like this:
12
12
13
-
### Project Structure
14
-
15
-
```sh
13
+
```shell
16
14
demo/
17
-
│
18
15
├── backend/
19
16
│ ├── app/
20
17
│ │ ├── checkpoint.program.json
@@ -24,31 +21,26 @@ demo/
24
21
├── frontend/
25
22
│ └── ... (your frontend code)
26
23
├── scripts/
27
-
│ ├── export_program.py
28
24
│ └── train.py (refer to the code examples to learn how to train programs)
For obvious reasons, you will need to have a separate logic to train your application. This script will specify the program architecture, training and evaluation procedure and will end up saving your program into a serializable JSON format.
120
-
121
-
Please refer to the code examples and [Training API](https://synalinks.github.io/synalinks/Synalinks%20API/Programs%20API/Program%20training%20API/) to learn how to train your programs.
122
-
123
-
To ease the migration, we'll also make a small script that export the trained program into our backend folder.
124
-
125
-
```python title="export_program.py"
126
-
import argparse
127
-
import os
128
-
import shutil
129
-
130
-
131
-
defmain():
132
-
parser = argparse.ArgumentParser(
133
-
description="Copy a serialized program to a specified directory."
134
-
)
135
-
parser.add_argument(
136
-
"filepath",
137
-
type=str,
138
-
help="Path to the file to be copied.",
139
-
)
140
-
parser.add_argument(
141
-
"output_dir",
142
-
type=str,
143
-
help="Path to the output directory.",
144
-
)
145
-
args = parser.parse_args()
146
-
147
-
ifnot args.filepath.endswith(".json"):
148
-
raiseValueError("The filepath must ends with `.json`")
149
-
150
-
ifnot os.path.exists(args.output_dir):
151
-
print(f"[*] Output directory does not exist. Creating: '{args.output_dir}'")
0 commit comments