Gramex 1.67 introduces MLHandler (to train, deploy and re-train models) and simpler names for micro-services.
MLHandler helps you embed ML models that can be trained on user-provided data.
You can embed a scikit-learn, statsmodels or tensorflow/keras model. For example:
url:
classifier:
pattern: /rugby
handler: MLHandler
kwargs:
model:
class: SVC # Embed sklearn.svm.SVC
target_col: ans # Predict the "ans" column
You can send HTTP requests to /rugby
to teach it that tall heavy boys make the male rugby team.
Suppose this data is in data.csv
:
| sex | height | weight | ans |
|-----|--------|--------|-----|
| m | 190 | 90 | Y |
| m | 185 | 85 | Y |
| m | 180 | 80 | Y |
| m | 150 | 80 | N |
| m | 180 | 60 | N |
| f | 180 | 80 | N |
You can append the data and train the model. (Typically using AJAX requests.)
# Append the data
$ curl -X POST -F "file=@data.csv" '/rugby?_action=append'
# Re-train the model
$ curl -X POST '/rugby?_action=retrain'
{"score": 1.0}
Now, you can check if a 190cm 80kg boy and a 150cm 80kg boy will get in.
$ curl '/rugby?sex=m&height=190&weight=80' # 190cm 80kg boy
["Y"] # will get in
$ curl '/rugby?sex=m&height=150&weight=80' # 150cm 80kg boy
["N"] # won't get in
As the users keep adding data and re-training the model, it keeps improving.
Handlers are now called micro-services, and identified in gramex.yaml
via
service:
instead of handler:
.
The names of these handlers is also simplified. So you can now use:
New version | instead of old version |
---|---|
service: Command |
handler: ProcessHandler |
service: Data |
handler: FormHandler |
service: Facebook |
handler: FacebookGraphHandler |
service: File |
handler: FileHandler |
service: Filter |
handler: FilterHandler |
service: Function |
handler: FunctionHandler |
service: ML |
handler: MLHandler |
service: Proxy |
handler: ProxyHandler |
service: Screenshot |
handler: CaptureHandler |
service: Slide |
handler: PPTXHandler |
service: Storage |
handler: DriveHandler |
service: Twitter |
handler: TwitterRESTHandler |
service: Websocket |
handler: WebSocketHandler |
Going forward, the new version will be preferred, and documentation accordingly. But the old version will continue to work until deprecated.
openpyxl
to read XLSX files, since xlrd
has deprecated support for XLSX files.
(By Naveen Manukonda)gramex <cmd> --help
prints help about that command.size: 0
ignores the cache limit. This is useful in stores like Azure
where setting a cache size limit causes an error. (By Mohammed Niyas)gramex.yaml
is updated while Gramex
is running.Gramex 1.68 will be released on 1 Feb 2021 and will feature a new “Forms” app. It’s like an embeddable Google Forms that you can use in any app.
The Gramex code base has:
openpyxl
instead of xlrd
See the Gramex installation and upgrade instructions
Note: Gramex 1.67 does not work with Python 3.8. We recommend Python 3.7.