feat: serve ML inference endpoints with Axum

This commit is contained in:
Asep Haryana Saputra
2026-05-23 09:48:54 +00:00
parent 36e4a49ca7
commit b4975819eb
2 changed files with 165 additions and 2 deletions
+41 -2
View File
@@ -4,6 +4,45 @@ mod image;
mod model;
mod routes;
fn main() {
println!("zeavis-ml-service");
use anyhow::Result;
use config::Config;
use model::ModelService;
use routes::{router, AppState};
use std::sync::Arc;
use tokio::net::TcpListener;
use tracing_subscriber::EnvFilter;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize tracing subscriber with EnvFilter
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
// Load configuration from environment
let config = Config::from_env()?;
// Create ModelService and wrap in Arc
let model = Arc::new(ModelService::new(&config.model_path, config.input_size));
// Log model status
tracing::info!(
model_loaded = model.is_loaded(),
model_path = ?config.model_path,
"Model service initialized"
);
// Create AppState
let state = AppState { model };
// Bind TcpListener to host:port
let addr = format!("{}:{}", config.host, config.port);
let listener = TcpListener::bind(&addr).await?;
tracing::info!(address = %addr, "Server listening");
// Serve with Axum
axum::serve(listener, router(state)).await?;
Ok(())
}