Skip to content

Commit

Permalink
feat/server behind feature (#404)
Browse files Browse the repository at this point in the history
* feat: move server behind feature flag

* don't include vulkan runtime by default

* fix test
  • Loading branch information
thewh1teagle authored Nov 19, 2024
1 parent c261a83 commit 2d1b022
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_special.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
include:
# Ubuntu 22.04
- platform: "ubuntu-22.04"
args: '--features "vulkan"'
args: '--features "vulkan" --features "server"'
pre-build-args: "--vulkan"
rust-version: "stable"
name: "ubuntu-22.04"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
matrix:
include:
- platform: "macos-latest" # for Arm based macs (M1 and above).
args: "--target aarch64-apple-darwin"
args: '--target aarch64-apple-darwin --features "server"'
- platform: "macos-latest" # for Intel based macs.
args: "--target x86_64-apple-darwin"
args: '--target x86_64-apple-darwin --features "server"'
- platform: "ubuntu-22.04" # Ubuntu 22.04 x86_64 (Works on 24.04 as well)
args: '--features "vulkan"'
args: '--features "vulkan,server"'
pre-build-args: "--vulkan"
- platform: "windows-latest" # Windows x86_64
args: '--target x86_64-pc-windows-msvc --features "vulkan"'
args: '--target x86_64-pc-windows-msvc --features "vulkan,server"'
pre-build-args: "--vulkan"

runs-on: ${{ matrix.platform }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows_special.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
include:
# Windows no AVX2
- platform: "windows-latest"
args: ''
args: '--features "server"'
pre-build-args: "--older-cpu"
name: "older-cpu"
rust-version: "stable"

# Windows no AVX2
- platform: "windows-latest"
args: '--features="vulkan"'
args: '--features="vulkan,server"'
pre-build-args: "--older-cpu --vulkan"
name: "older-cpu-vulkan"
rust-version: "stable"
Expand Down
5 changes: 4 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ serde = { version = "1.0.195", features = ["derive"] }
num = "0.4.1"
once_cell = "1.19.0"
which = "6.0.1"
utoipa = { version = "4.2.3", features = ["axum_extras"] }
tracing = { version = "0.1.40", features = ["log"] }
eyre = { workspace = true }
hound = "3.5.1"
Expand All @@ -32,6 +31,9 @@ serde_json = { workspace = true }
futures-util = "0.3.30"
pyannote-rs = "0.2.7"

# Server
utoipa = { version = "4.2.3", features = ["axum_extras"], optional = true }

[dev-dependencies]

serial_test = "3.1.1"
Expand All @@ -49,3 +51,4 @@ openblas = ["whisper-rs/openblas"]
metal = ["whisper-rs/metal"]
rocm = ["whisper-rs/hipblas"]
vulkan = ["whisper-rs/vulkan"]
server = ["dep:utoipa"]
5 changes: 3 additions & 2 deletions core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use core::fmt;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
#[cfg_attr(feature = "server", derive(utoipa::ToSchema))]

pub struct TranscribeOptions {
pub path: String,
pub lang: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn test_transcribe() {
word_timestamps: None,
};
let start = Instant::now();
let result = crate::transcribe::transcribe(&ctx, options, None, None, None, None);
let result = crate::transcribe::transcribe(&ctx, options, None, None, None, None, None);
println!("{:?}", result);
println!(
"Elapsed time: {:.2} seconds",
Expand Down
7 changes: 4 additions & 3 deletions core/src/transcript.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use eyre::Result;
use num::integer::div_floor;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

pub fn format_timestamp(seconds: i64, always_include_hours: bool, decimal_marker: &str) -> String {
assert!(seconds >= 0, "non-negative timestamp expected");
Expand All @@ -25,13 +24,15 @@ pub fn format_timestamp(seconds: i64, always_include_hours: bool, decimal_marker
format!("{hours_marker}{minutes:02}:{seconds:02}{decimal_marker}{milliseconds:03}")
}

#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "server", derive(utoipa::ToSchema))]
pub struct Transcript {
pub processing_time_sec: u64,
pub segments: Vec<Segment>,
}

#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "server", derive(utoipa::ToSchema))]
pub struct Segment {
pub start: i64,
pub stop: i64,
Expand Down
13 changes: 10 additions & 3 deletions desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ futures = "0.3.30"
cpal = "0.15.3"
hound = "3.5.1"
rand = "0.8.5"
axum = "0.7.5"
utoipa = { version = "4.2.3", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "7.1.0", features = ["axum"] }

# Server
axum = { version = "0.7.5", optional = true }
utoipa = { version = "4.2.3", features = ["axum_extras"], optional = true }
utoipa-swagger-ui = { version = "7.1.0", features = ["axum"], optional = true }

# Log
tracing = { version = "0.1.40", features = ["log"] }
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }

chrono = "0.4.38"
crash-handler = "0.6.2"
urlencoding = "2.1.3"
Expand Down Expand Up @@ -84,9 +89,11 @@ objc_id = "0.1"
core-graphics-helmer-fork = "0.24.0"

[features]
default = []
cuda = ["vibe_core/cuda"]
coreml = ["vibe_core/coreml"]
metal = ["vibe_core/metal"]
openblas = ["vibe_core/openblas"]
rocm = ["vibe_core/rocm"]
vulkan = ["vibe_core/vulkan", "dep:ash"]
server = ["dep:utoipa", "dep:utoipa-swagger-ui", "dep:axum", "vibe_core/server"]
6 changes: 3 additions & 3 deletions desktop/src-tauri/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use vibe_core::config::TranscribeOptions;
use vibe_core::transcribe;

use crate::cmd::get_models_folder;
use crate::server;

/// Attach to console if cli detected in Windows
#[cfg(all(windows, not(debug_assertions)))]
Expand Down Expand Up @@ -115,7 +114,7 @@ struct Args {
diarize_speaker_id_model: Option<String>,

/// Run http server
#[arg(long)]
#[cfg_attr(feature = "server", clap(long))]
server: bool,

#[arg(long, default_value = "0.0.0.0")]
Expand Down Expand Up @@ -180,8 +179,9 @@ pub async fn run(app_handle: &AppHandle) -> Result<()> {
args.format = "json".into();
}

#[cfg(feature = "server")]
if args.server {
server::run(app_handle.clone(), args.host, args.port).await?;
crate::server::run(app_handle.clone(), args.host, args.port).await?;
}
let lang = language_name_to_whisper_lang(&args.language)?;
let options = TranscribeOptions {
Expand Down
6 changes: 3 additions & 3 deletions desktop/src-tauri/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ impl Default for FfmpegOptions {
}

impl FfmpegOptions {
pub fn to_vec(&mut self) -> Vec<String> {
pub fn to_vec(&self) -> Vec<String> {
let mut cmd = Vec::<String>::new();
if let Some(custom_cmd) = &self.custom_command {
cmd.extend(custom_cmd.split_whitespace().map(|s| s.to_string()));
} else if self.normalize_loudness {
cmd.extend(["-af".to_string(), "loudnorm=I=-16:TP=-1.5:LRA=11".to_string()]);
}
return cmd;
cmd
}
}

Expand All @@ -245,7 +245,7 @@ pub async fn transcribe(
options: vibe_core::config::TranscribeOptions,
model_context_state: State<'_, Mutex<Option<ModelContext>>>,
diarize_options: DiarizeOptions,
mut ffmpeg_options: FfmpegOptions,
ffmpeg_options: FfmpegOptions,
) -> Result<Transcript> {
let model_context = model_context_state.lock().await;
if model_context.is_none() {
Expand Down
3 changes: 3 additions & 0 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ mod cli;
mod cmd;
mod config;
mod panic_hook;

#[cfg(feature = "server")]
mod server;

mod setup;
mod utils;
use tauri::{Emitter, Manager};
Expand Down
4 changes: 2 additions & 2 deletions desktop/src-tauri/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use tauri::Manager;
use tokio::sync::Mutex;
use utoipa::{OpenApi, ToSchema};
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
use vibe_core::config::TranscribeOptions;
use vibe_core::transcript::{Segment, Transcript};
Expand Down Expand Up @@ -39,7 +39,7 @@ pub async fn run(app_handle: tauri::AppHandle, host: String, port: u16) -> eyre:
Ok(())
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
struct LoadPayload {
pub model_path: String,
pub gpu_device: Option<i32>,
Expand Down
3 changes: 1 addition & 2 deletions desktop/src-tauri/tauri.windows.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"timestampUrl": "http://timestamp.digicert.com"
},
"resources": {
"ffmpeg\\bin\\x64\\*": "./",
"vulkan_runtime\\x64\\*.dll": "./"
"ffmpeg\\bin\\x64\\*": "./"
}
}
}

0 comments on commit 2d1b022

Please sign in to comment.