Skip to content

Commit 4314501

Browse files
mylibrarSuqi Sun
andauthored
All more instructions in README and fix nlp.py (#213)
* Fix validation and datapack serialization in nlp.py * Add more detailed instruction in README Co-authored-by: Suqi Sun <[email protected]>
1 parent abde3ef commit 4314501

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ At any time, you can still load the example projects:
4343
stave load-samples
4444
```
4545

46+
By default the Stave server runs at http://localhost:8888. If you need to switch the port, you can add `-n` to specify the port number. For example, the following command will start a Stave service at http://localhost:8002.
47+
```bash
48+
stave start -n 8002
49+
```
50+
For more options to start Stave server, refer to:
51+
```bash
52+
stave start -h
53+
```
4654
#### Stave Configuration
4755
After you start the Stave server, a `.stave/` folder is automatically created under your home directory `~`. It has the following structure:
4856
```
@@ -60,12 +68,68 @@ You may follow the prompts to interactively set up the configuration:
6068
```bash
6169
stave config -i
6270
```
63-
For more information, refer to:
71+
Stave CLI allows you to configure the database file, log file, the allowed hosts, etc. For more options, run
6472
```bash
6573
stave config -h
6674
```
75+
and you shall see the following help message:
76+
```bash
77+
usage: stave config [-h] [-i] [-s DJANGO_SETTINGS_MODULE] [-d DB_FILE]
78+
[-l LOG_FILE] [-a ALLOWED_HOSTS [ALLOWED_HOSTS ...]]
79+
80+
optional arguments:
81+
-h, --help show this help message and exit
82+
-i, --interact-config
83+
Interactively set up the configuration
84+
-s DJANGO_SETTINGS_MODULE, --django-settings-module DJANGO_SETTINGS_MODULE
85+
Module path to settings.py of django project. If you
86+
have not set up any django project, you should leave
87+
this field empty and stave will use its default
88+
configuration. To set this field you should already
89+
have a django project and the 'settings.py' file under
90+
your project must be accessible from PYTHONPATH so
91+
that django can import it as a module. Example:
92+
'myproject.settings'
93+
-d DB_FILE, --db-file DB_FILE
94+
Path to database file of Stave
95+
-l LOG_FILE, --log-file LOG_FILE
96+
Path to log file for logging
97+
-a ALLOWED_HOSTS [ALLOWED_HOSTS ...], --allowed-hosts ALLOWED_HOSTS [ALLOWED_HOSTS ...]
98+
A list of strings representing the host/domain names
99+
that stave can serve.
100+
```
101+
For example, you can change the path of database file by running:
102+
```bash
103+
stave config -d ~/db.sqlite3
104+
```
105+
You may also add your own host names to the allowed hosts that Stave can serve:
106+
```bash
107+
stave config -a localhost myhost1.com myhost2.com
108+
```
109+
110+
#### Import and Export
111+
Stave provides a set of interfaces that allow you to import/export projects from/to disk. This is useful when you need to transfer Stave projects between backend database and local storage.
112+
113+
To export a project, you need to specify the path to store the project and its database id (which can be retrieved from URL, e.g., the id of project at http://localhost:8888/project/3 is 3). For example, the following command will save project with `id=3` to `~/project_3`:
114+
```bash
115+
stave export ~/project_3 3
116+
```
117+
Note that you will be prompted to enter your username and password before moving forward.
118+
119+
Now that you've saved a Stave project to a directory, you can either render this project in viewer mode
120+
```bash
121+
stave start -o -p ~/project_3
122+
```
123+
or import it to the database (which also requires authentication with username and password)
124+
```bash
125+
stave import ~/project_3
126+
```
127+
`stave import` is also useful when you use [StaveProcessor](https://github.com/asyml/forte/blob/master/forte/processors/stave/stave_processor.py#L46) inside a forte pipeline and want to save the generated visualization to database. `StaveProcessor` normally would save a Stave project to a folder (by default the name of folder is `Auto generated project`), and you can import this folder into stave backend by running
128+
```bash
129+
stave import PATH_TO_STAVE_PROJECT
130+
```
67131
68-
#### More about the command line tool:
132+
#### More about the command line tool
69133
To learn more about Stave CLI, run the following command to see the help message:
70134
```bash
71135
stave -h

simple-backend/stave_backend/handlers/nlp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def expected_types_and_attributes(cls):
4646
}
4747

4848
#Create the pipeline and add the processor.
49-
pipeline = Pipeline[DataPack](do_init_type_check=True)
49+
pipeline = Pipeline[DataPack](
50+
do_init_type_check=remote_configs.get("doValidation")
51+
)
5052
pipeline.set_reader(RawDataDeserializeReader())
5153
pipeline.add(RemoteProcessor(), config={
5254
"url": remote_configs.get("pipelineUrl"),
@@ -107,7 +109,7 @@ def run_pipeline(request, document_id: int):
107109
response: JsonResponse
108110
if pipeline:
109111
processedPack = pipeline.process([docJson['textPack']])
110-
doc.textPack = processedPack.serialize(True)
112+
doc.textPack = processedPack.to_string(True)
111113
doc.save()
112114
response = JsonResponse(model_to_dict(doc), safe=False)
113115
else:

0 commit comments

Comments
 (0)