2026-05-23 09:23:38 +00:00
|
|
|
mod config;
|
2026-05-23 09:33:15 +00:00
|
|
|
mod error;
|
2026-05-23 09:38:10 +00:00
|
|
|
mod image;
|
2026-05-23 09:41:30 +00:00
|
|
|
mod model;
|
2026-05-23 09:33:15 +00:00
|
|
|
mod routes;
|
2026-06-07 18:04:50 +07:00
|
|
|
mod telemetry;
|
2026-05-23 09:23:38 +00:00
|
|
|
|
2026-05-23 09:48:54 +00:00
|
|
|
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()?;
|
|
|
|
|
|
2026-06-11 21:53:43 +00:00
|
|
|
// Create ModelService with calibration and wrap in Arc
|
|
|
|
|
let model = Arc::new(ModelService::with_calibration(
|
|
|
|
|
&config.model_path,
|
|
|
|
|
config.input_size,
|
|
|
|
|
config.temperature,
|
|
|
|
|
config.conf_threshold_high,
|
|
|
|
|
config.conf_threshold_low,
|
|
|
|
|
));
|
2026-05-23 09:48:54 +00:00
|
|
|
tracing::info!(
|
|
|
|
|
model_loaded = model.is_loaded(),
|
|
|
|
|
model_path = ?config.model_path,
|
2026-06-11 21:53:43 +00:00
|
|
|
temperature = config.temperature,
|
|
|
|
|
conf_high = config.conf_threshold_high,
|
|
|
|
|
conf_low = config.conf_threshold_low,
|
2026-05-23 09:48:54 +00:00
|
|
|
"Model service initialized"
|
|
|
|
|
);
|
|
|
|
|
|
2026-06-07 18:04:50 +07:00
|
|
|
// Set model load status metric
|
|
|
|
|
telemetry::model_load_status().set(if model.is_loaded() { 1.0 } else { 0.0 });
|
|
|
|
|
|
2026-05-23 09:48:54 +00:00
|
|
|
// 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(())
|
2026-05-23 09:23:38 +00:00
|
|
|
}
|