Skip to content

Commit

Permalink
Add Rust workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniskore authored Aug 20, 2024
1 parent 1e78a5b commit c56e07c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on: [push, pull_request]

name: CI

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/[email protected]
- run: cargo check
working-directory: web_api

test:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/[email protected]
- run: cargo test
working-directory: web_api

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/[email protected]
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check
working-directory: web_api

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/[email protected]
- run: rustup component add clippy
- run: cargo clippy -- -D warnings
working-directory: web_api
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Build Status](https://github.com/deniskore/py-ml-to-rs/actions/workflows/rust.yml/badge.svg)

# Intro
A friend of mine asked me to demonstrate how to load a model trained in Python into a Rust service. In response, this repository showcases the entire process of training a machine learning model to distinguish between various text encodings, achieving around 98.5% validation accuracy, using data sourced from the English Wiktionary.
Subsequently, the trained model is seamlessly integrated into a Rust-based microservice, utilizing the ntex-rs. This implementation is streamlined with minimal dependencies, ensuring a lightweight and efficient service.
Expand Down
8 changes: 6 additions & 2 deletions web_api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ mod model;
#[ntex::main]
async fn main() -> std::io::Result<()> {
let model = Arc::new(
model::load_model("../../model/detector".to_string(), "predict_input", "predict_output")
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?,
model::load_model(
"../../model/detector".to_string(),
"predict_input",
"predict_output",
)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?,
);

web::server(move || {
Expand Down

0 comments on commit c56e07c

Please sign in to comment.