- Add Qwen3-VL dynamic management (start/stop/status CLI) - Add CLIP + Qwen3-VL cascade detection strategy - Add Vision CLI commands (vision start/stop/status, detect) - Add cascade_vision processor module - Add clip processor module - Add qwen_vl_manager module Changes: - scripts/start_qwen3vl.sh, stop_qwen3vl.sh: Qwen3-VL management scripts - src/core/vision/: Qwen3-VL manager module - src/core/processor/cascade_vision.rs: CLIP + Qwen3-VL cascade logic - src/core/processor/clip.rs: CLIP classification and detection - src/api/clip_api.rs: CLIP API endpoints - src/cli/vision.rs: Vision CLI implementation - src/cli/args.rs: Add Vision and Detect commands - src/main.rs: Integrate Vision CLI - src/core/mod.rs: Add vision module - src/core/processor/mod.rs: Add cascade_vision module
379 lines
9.5 KiB
Rust
379 lines
9.5 KiB
Rust
//! Momentry Core - Digital asset management system with video analysis and RAG
|
|
//!
|
|
//! This is the main entry point for the CLI application.
|
|
|
|
use anyhow::Result;
|
|
use clap::Parser;
|
|
|
|
// Local modules
|
|
mod cli;
|
|
mod processing;
|
|
|
|
fn init_tracing() {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
|
.with_target(true)
|
|
.init();
|
|
}
|
|
|
|
fn load_env() {
|
|
let _ = dotenv::from_filename("/Users/accusys/momentry_core_0.1/.env");
|
|
}
|
|
|
|
use cli::*;
|
|
use processing::handlers::*;
|
|
|
|
/// Main entry point
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
load_env();
|
|
init_tracing();
|
|
let cli = Cli::parse();
|
|
|
|
match cli.command {
|
|
Commands::Register { path } => {
|
|
handle_register(&path).await?;
|
|
}
|
|
Commands::Process {
|
|
target,
|
|
modules,
|
|
cloud,
|
|
force,
|
|
resume,
|
|
} => {
|
|
handle_process(&target, modules, cloud, force, resume).await?;
|
|
}
|
|
Commands::Chunk { uuid } => {
|
|
handle_chunk(&uuid).await?;
|
|
}
|
|
Commands::StoreAsrx { uuid } => {
|
|
handle_store_asrx(&uuid).await?;
|
|
}
|
|
Commands::Story { uuid } => {
|
|
handle_story(&uuid).await?;
|
|
}
|
|
Commands::Vectorize { uuid } => {
|
|
handle_vectorize(&uuid).await?;
|
|
}
|
|
Commands::Phase1 { uuid } => {
|
|
handle_phase1(&uuid).await?;
|
|
}
|
|
Commands::Complete { uuid } => {
|
|
handle_complete(&uuid).await?;
|
|
}
|
|
Commands::Play { target } => {
|
|
handle_play(&target).await?;
|
|
}
|
|
Commands::Watch { directories } => {
|
|
handle_watch(directories).await?;
|
|
}
|
|
Commands::System { gpu } => {
|
|
handle_system(gpu).await?;
|
|
}
|
|
Commands::Server { host, port } => {
|
|
handle_server(&host, port).await?;
|
|
}
|
|
Commands::Worker {
|
|
max_concurrent,
|
|
poll_interval,
|
|
batch_size,
|
|
} => {
|
|
handle_worker(max_concurrent, poll_interval, batch_size).await?;
|
|
}
|
|
Commands::Query { query } => {
|
|
handle_query(&query).await?;
|
|
}
|
|
Commands::Lookup { path } => {
|
|
handle_lookup(&path).await?;
|
|
}
|
|
Commands::Resolve { uuid } => {
|
|
handle_resolve(&uuid).await?;
|
|
}
|
|
Commands::Thumbnails { uuid, count } => {
|
|
handle_thumbnails(uuid, count).await?;
|
|
}
|
|
Commands::Status { uuid } => {
|
|
handle_status(uuid).await?;
|
|
}
|
|
Commands::Backup { action, days } => {
|
|
handle_backup(&action, days).await?;
|
|
}
|
|
Commands::ApiKey {
|
|
action,
|
|
name,
|
|
key_type,
|
|
ttl,
|
|
key,
|
|
} => {
|
|
handle_api_key(action, name, key_type, ttl, key).await?;
|
|
}
|
|
Commands::Gitea {
|
|
action,
|
|
username,
|
|
password,
|
|
token_name,
|
|
scopes,
|
|
} => {
|
|
handle_gitea(action, username, password, token_name, scopes).await?;
|
|
}
|
|
Commands::N8n {
|
|
action,
|
|
api_key,
|
|
label,
|
|
expires_in_days,
|
|
} => {
|
|
handle_n8n(action, api_key, label, expires_in_days).await?;
|
|
}
|
|
Commands::Detect {
|
|
image,
|
|
objects,
|
|
cascade,
|
|
threshold,
|
|
} => {
|
|
cli::vision::handle_detect_command(image, objects, cascade, threshold).await?;
|
|
}
|
|
Commands::Vision(cmd) => {
|
|
cli::vision::handle_vision_command(cmd).await?;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle register command
|
|
async fn handle_register(path: &str) -> Result<()> {
|
|
println!("Registering video: {}", path);
|
|
|
|
// TODO: Implement registration logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle process command
|
|
async fn handle_process(
|
|
target: &str,
|
|
modules: Option<Vec<String>>,
|
|
cloud: Option<Vec<String>>,
|
|
force: bool,
|
|
resume: bool,
|
|
) -> Result<()> {
|
|
println!("Processing video: {}", target);
|
|
println!("Modules: {:?}", modules);
|
|
println!("Cloud modules: {:?}", cloud);
|
|
println!("Force: {}, Resume: {}", force, resume);
|
|
|
|
// TODO: Implement processing logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle chunk command
|
|
async fn handle_chunk(uuid: &str) -> Result<()> {
|
|
println!("Generating chunks for: {}", uuid);
|
|
|
|
// TODO: Implement chunk logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle story command
|
|
async fn handle_story(uuid: &str) -> Result<()> {
|
|
println!("Generating story for: {}", uuid);
|
|
|
|
// TODO: Implement story logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle vectorize command
|
|
async fn handle_vectorize(uuid: &str) -> Result<()> {
|
|
println!("Vectorizing chunks for: {}", uuid);
|
|
|
|
// TODO: Implement vectorize logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle play command
|
|
async fn handle_play(target: &str) -> Result<()> {
|
|
println!("Playing video: {}", target);
|
|
|
|
// TODO: Implement play logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle watch command
|
|
async fn handle_watch(directories: Option<String>) -> Result<()> {
|
|
println!("Watching directories: {:?}", directories);
|
|
|
|
// TODO: Implement watch logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle system command
|
|
async fn handle_system(gpu: bool) -> Result<()> {
|
|
println!("Checking system resources...");
|
|
|
|
// TODO: Implement proper system resource checking
|
|
println!("System Information:");
|
|
println!(" CPU: (would show CPU info)");
|
|
println!(" Memory: (would show memory info)");
|
|
|
|
if gpu {
|
|
println!("GPU details: (would show GPU info if available)");
|
|
}
|
|
|
|
println!("(System resource checking would be implemented here)");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle server command
|
|
async fn handle_server(host: &str, port: Option<u16>) -> Result<()> {
|
|
let port = port.unwrap_or(3002);
|
|
println!("Starting API server on {}:{}", host, port);
|
|
|
|
// Start the actual API server
|
|
momentry_core::api::start_server(host, port).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle worker command
|
|
async fn handle_worker(
|
|
max_concurrent: Option<usize>,
|
|
poll_interval: Option<u64>,
|
|
batch_size: Option<i32>,
|
|
) -> Result<()> {
|
|
use momentry_core::core::db::{Database, PostgresDb, RedisClient};
|
|
use momentry_core::worker::{JobWorker, WorkerConfig};
|
|
|
|
println!("Starting job worker");
|
|
println!("Max concurrent: {:?}", max_concurrent);
|
|
println!("Poll interval: {:?}", poll_interval);
|
|
println!("Batch size: {:?}", batch_size);
|
|
|
|
let config = WorkerConfig {
|
|
max_concurrent: max_concurrent.unwrap_or(2),
|
|
poll_interval_secs: poll_interval.unwrap_or(5),
|
|
enabled: true,
|
|
batch_size: batch_size.unwrap_or(10),
|
|
processor_timeout_secs: 3600,
|
|
};
|
|
|
|
let db = PostgresDb::init().await?;
|
|
let redis = RedisClient::new()?;
|
|
|
|
let worker = JobWorker::new(
|
|
std::sync::Arc::new(db),
|
|
std::sync::Arc::new(redis),
|
|
config.clone(),
|
|
);
|
|
|
|
println!(
|
|
"Starting worker with max_concurrent={}, poll_interval={}s",
|
|
config.max_concurrent, config.poll_interval_secs
|
|
);
|
|
|
|
worker.run().await?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle query command
|
|
async fn handle_query(query: &str) -> Result<()> {
|
|
println!("Querying: {}", query);
|
|
|
|
// TODO: Implement query logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle lookup command
|
|
async fn handle_lookup(path: &str) -> Result<()> {
|
|
println!("Looking up UUID for path: {}", path);
|
|
|
|
// TODO: Implement lookup logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle resolve command
|
|
async fn handle_resolve(uuid: &str) -> Result<()> {
|
|
println!("Resolving path for UUID: {}", uuid);
|
|
|
|
// TODO: Implement resolve logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle thumbnails command
|
|
async fn handle_thumbnails(uuid: Option<String>, count: u32) -> Result<()> {
|
|
println!("Generating thumbnails");
|
|
println!("UUID: {:?}", uuid);
|
|
println!("Count: {}", count);
|
|
|
|
// TODO: Implement thumbnails logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle status command
|
|
async fn handle_status(uuid: Option<String>) -> Result<()> {
|
|
println!("Checking storage status");
|
|
println!("UUID: {:?}", uuid);
|
|
|
|
// TODO: Implement status logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle backup command
|
|
async fn handle_backup(action: &str, days: Option<u32>) -> Result<()> {
|
|
println!("Backup action: {}", action);
|
|
println!("Days to keep: {:?}", days);
|
|
|
|
// TODO: Implement backup logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle API key command
|
|
async fn handle_api_key(
|
|
action: ApiKeyAction,
|
|
name: Option<String>,
|
|
key_type: Option<String>,
|
|
ttl: Option<i64>,
|
|
key: Option<String>,
|
|
) -> Result<()> {
|
|
println!("API Key action: {:?}", action);
|
|
println!("Name: {:?}", name);
|
|
println!("Key type: {:?}", key_type);
|
|
println!("TTL: {:?}", ttl);
|
|
println!("Key: {:?}", key);
|
|
|
|
// TODO: Implement API key logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle Gitea command
|
|
async fn handle_gitea(
|
|
action: GiteaAction,
|
|
username: Option<String>,
|
|
password: Option<String>,
|
|
token_name: Option<String>,
|
|
scopes: Option<String>,
|
|
) -> Result<()> {
|
|
println!("Gitea action: {:?}", action);
|
|
println!("Username: {:?}", username);
|
|
println!("Token name: {:?}", token_name);
|
|
println!("Scopes: {:?}", scopes);
|
|
|
|
// TODO: Implement Gitea logic
|
|
Ok(())
|
|
}
|
|
|
|
/// Handle n8n command
|
|
async fn handle_n8n(
|
|
action: N8nAction,
|
|
api_key: Option<String>,
|
|
label: Option<String>,
|
|
expires_in_days: Option<i64>,
|
|
) -> Result<()> {
|
|
println!("n8n action: {:?}", action);
|
|
println!("API key: {:?}", api_key);
|
|
println!("Label: {:?}", label);
|
|
println!("Expires in days: {:?}", expires_in_days);
|
|
|
|
// TODO: Implement n8n logic
|
|
Ok(())
|
|
}
|