Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat(models): a download source setting, hf-mirror, and downloads that resume

Jareer7cf921d37eaa
diff --git a/engine/crates/concat-host/src/cutout.rs b/engine/crates/concat-host/src/cutout.rs
index 2bbc3499..8d6eb786 100644
--- a/engine/crates/concat-host/src/cutout.rs
+++ b/engine/crates/concat-host/src/cutout.rs
@@ -405,8 +405,9 @@ pub(crate) fn fetch(
return std::fs::rename(&partial, file)
.map_err(|error| format!("could not finish {}: {error}", file.display()));
}
+ // The partial stays for the next source, or the next time:
+ // whichever answers takes up where this one stopped.
Err(error) => {
- let _ = std::fs::remove_file(&partial);
if cancel.load(Ordering::Relaxed) {
return Err(error);
}
@@ -417,7 +418,8 @@ pub(crate) fn fetch(
Err(format!("could not fetch the {} model: {last}", spec.file))
}
-/// One attempt at one URL: straight into `partial`, reporting as it goes.
+/// One attempt at one URL, through the shared downloader: into `partial`,
+/// taking up from whatever of it is already there.
fn stream(
url: &str,
partial: &Path,
@@ -425,53 +427,15 @@ fn stream(
cancel: &AtomicBool,
progress: &mut dyn FnMut(Progress),
) -> Result<(), String> {
- use std::io::{Read, Write};
-
- // A stalled connection blocks in `read` with the cancel flag
- // unreachable; thirty seconds without a byte means it is dead.
- let agent = ureq::AgentBuilder::new()
- .timeout_connect(std::time::Duration::from_secs(20))
- .timeout_read(std::time::Duration::from_secs(30))
- .build();
- let response = agent
- .get(url)
- .call()
- .map_err(|error| format!("{url} did not answer: {error}"))?;
- let total = response
- .header("Content-Length")
- .and_then(|value| value.parse::<u64>().ok())
- .unwrap_or(estimate);
-
- let mut out = std::fs::File::create(partial)
- .map_err(|error| format!("could not create {}: {error}", partial.display()))?;
- let mut reader = response.into_reader();
- let mut buffer = [0u8; 64 * 1024];
- let mut received = 0u64;
- let mut reported = 0u64;
- loop {
- if cancel.load(Ordering::Relaxed) {
- return Err("cutout analysis cancelled".to_owned());
- }
- let read = reader
- .read(&mut buffer)
- .map_err(|error| format!("model download interrupted: {error}"))?;
- if read == 0 {
- break;
- }
- out.write_all(&buffer[..read])
- .map_err(|error| format!("could not write the model: {error}"))?;
- received += read as u64;
- if received - reported >= 2 * 1024 * 1024 {
- reported = received;
- progress(Progress::Fetching { received, total });
- }
- }
- out.flush()
- .map_err(|error| format!("could not write the model: {error}"))?;
- if received == 0 {
- return Err(format!("{url} came back empty"));
- }
- Ok(())
+ crate::models::download(
+ url,
+ partial,
+ estimate,
+ cancel,
+ "cutout analysis cancelled",
+ &mut |received, total| progress(Progress::Fetching { received, total }),
+ )
+ .map(|_| ())
}
/// Every instant the ranges need that the store lacks, ascending, once.
diff --git a/engine/crates/concat-host/src/models.rs b/engine/crates/concat-host/src/models.rs
index 391fb551..c837b7c0 100644
--- a/engine/crates/concat-host/src/models.rs
+++ b/engine/crates/concat-host/src/models.rs
@@ -34,19 +34,251 @@ pub const REPO: &str = "jub0t/Concat";
/// in `models/manifest.toml`; the check script enforces that.
pub const RELEASE: &str = "models-v1";
-/// Where `file` is mirrored.
+/// Where `file` is mirrored: Concat's own release.
pub fn mirror(file: &str) -> String {
format!("https://github.com/{REPO}/releases/download/{RELEASE}/{file}")
}
-/// Where to try for `file`, in order: our mirror, then the upstream it was
-/// filled from.
+/// A Hugging Face repository holding the same mirror, when there is one -
+/// "owner/name". Hugging Face is what hf-mirror.com mirrors in turn, which
+/// is how the models reach the people GitHub's downloads do not. Empty
+/// until the mirror workflow fills one.
+pub const HF_REPO: &str = "";
+
+/// The host that mirrors Hugging Face for mainland China.
+const HF_MIRROR_HOST: &str = "https://hf-mirror.com/";
+
+/// `url`, served by hf-mirror.com instead, for a Hugging Face URL; `None`
+/// for any other host, which that mirror does not carry.
+pub fn hf_mirror(url: &str) -> Option<String> {
+ url.strip_prefix("https://huggingface.co/")
+ .or_else(|| url.strip_prefix("https://hf.co/"))
+ .map(|rest| format!("{HF_MIRROR_HOST}{rest}"))
+}
+
+/// Which source a download tries first. The rest still follow: a
+/// preference is where to look first, never the only place to look.
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
+pub enum SourcePreference {
+ /// Concat's mirror, then Hugging Face, then upstream, then hf-mirror.
+ #[default]
+ Auto,
+ /// Concat's own release first.
+ Mirror,
+ /// hf-mirror.com first: for mainland China, where GitHub's downloads
+ /// crawl and huggingface.co needs a VPN, and hf-mirror.com does not.
+ HfMirror,
+ /// The third party each model was mirrored from, first.
+ Upstream,
+ /// A base URL of one's own, with the model's file name appended: a
+ /// corporate mirror, a self-hosted copy.
+ Custom,
+}
+
+impl SourcePreference {
+ /// Every preference, in the order a menu lists them.
+ pub const ALL: [SourcePreference; 5] = [
+ SourcePreference::Auto,
+ SourcePreference::Mirror,
+ SourcePreference::HfMirror,
+ SourcePreference::Upstream,
+ SourcePreference::Custom,
+ ];
+
+ /// The name a preferences file stores.
+ pub fn name(self) -> &'static str {
+ match self {
+ SourcePreference::Auto => "auto",
+ SourcePreference::Mirror => "mirror",
+ SourcePreference::HfMirror => "hf-mirror",
+ SourcePreference::Upstream => "upstream",
+ SourcePreference::Custom => "custom",
+ }
+ }
+
+ /// The preference a stored name means; `Auto` for one nobody stores.
+ pub fn parse(name: &str) -> Self {
+ Self::ALL
+ .into_iter()
+ .find(|preference| preference.name() == name)
+ .unwrap_or_default()
+ }
+}
+
+/// The preference in force, and the base URL a custom one points at.
+static PREFERENCE: std::sync::RwLock<(SourcePreference, String)> =
+ std::sync::RwLock::new((SourcePreference::Auto, String::new()));
+
+/// Sets where downloads look first. From the window, when the preference
+/// is read from disk and whenever it is changed.
+pub fn set_preference(preference: SourcePreference, custom_base: &str) {
+ if let Ok(mut held) = PREFERENCE.write() {
+ *held = (
+ preference,
+ custom_base.trim().trim_end_matches('/').to_owned(),
+ );
+ }
+}
+
+/// Where downloads look first, and the custom base URL.
+pub fn preference() -> (SourcePreference, String) {
+ PREFERENCE
+ .read()
+ .map(|held| held.clone())
+ .unwrap_or_default()
+}
+
+/// Where to try for `file`, in order, for the preference in force.
///
-/// Two and not one because a mirror that cannot be reached - a proxy that
-/// blocks our host, a release still being published, a region that cannot
-/// see it - should cost a retry rather than a feature.
-pub fn sources(file: &str, upstream: &str) -> [String; 2] {
- [mirror(file), upstream.to_owned()]
+/// Every source that could hold the file is in the list once; the
+/// preference only decides which comes first. A mirror that cannot be
+/// reached - a proxy that blocks a host, a release still being published,
+/// a region that cannot see it - should cost a retry rather than a
+/// feature, and the bytes are checked against the same digest whichever
+/// source they came from.
+pub fn sources(file: &str, upstream: &str) -> Vec<String> {
+ let (preference, custom_base) = preference();
+ sources_for(file, upstream, preference, &custom_base)
+}
+
+fn sources_for(
+ file: &str,
+ upstream: &str,
+ preference: SourcePreference,
+ custom_base: &str,
+) -> Vec<String> {
+ let github = mirror(file);
+ let hugging_face = (!HF_REPO.is_empty())
+ .then(|| format!("https://huggingface.co/{HF_REPO}/resolve/main/{file}"));
+ let custom = (!custom_base.is_empty()).then(|| format!("{custom_base}/{file}"));
+ // hf-mirror carries whatever Hugging Face does: our own repository
+ // there, and any upstream that lives there.
+ let hf_mirrored: Vec<String> = hugging_face
+ .iter()
+ .map(String::as_str)
+ .chain(std::iter::once(upstream))
+ .filter_map(hf_mirror)
+ .collect();
+
+ let mut ordered: Vec<String> = Vec::new();
+ let mut push = |url: String| {
+ if !url.is_empty() && !ordered.contains(&url) {
+ ordered.push(url);
+ }
+ };
+ match preference {
+ SourcePreference::Auto | SourcePreference::Mirror => {}
+ SourcePreference::HfMirror => hf_mirrored.iter().cloned().for_each(&mut push),
+ SourcePreference::Upstream => push(upstream.to_owned()),
+ SourcePreference::Custom => custom.iter().cloned().for_each(&mut push),
+ }
+ push(github);
+ hugging_face.iter().cloned().for_each(&mut push);
+ push(upstream.to_owned());
+ hf_mirrored.iter().cloned().for_each(&mut push);
+ custom.iter().cloned().for_each(&mut push);
+ ordered
+}
+
+/// One attempt at one URL, streamed into `partial`, taking up from
+/// however much of `partial` is already there.
+///
+/// A model is hundreds of megabytes, and the links this matters most on
+/// are the slow ones: a dropped connection at 280 MB of 300 used to start
+/// again from nothing. The bytes already on disk are kept and the server
+/// is asked for the rest, by a Range request every host on the list
+/// honours; a server that answers with the whole file instead is taken
+/// at its word and the partial started over. What arrives is checked
+/// against the model's digest afterwards, so a partial finished from a
+/// second source that happens to hold different bytes is refused there,
+/// not trusted here.
+///
+/// `progress` is called with (received, total) every couple of megabytes.
+/// `cancelled` is the error to return when `cancel` is set: the caller's
+/// words, since it knows what was being fetched.
+pub fn download(
+ url: &str,
+ partial: &Path,
+ estimate: u64,
+ cancel: &std::sync::atomic::AtomicBool,
+ cancelled: &str,
+ progress: &mut dyn FnMut(u64, u64),
+) -> Result<(u64, u64), String> {
+ use std::io::{Read, Write};
+ use std::sync::atomic::Ordering;
+
+ let already = std::fs::metadata(partial)
+ .map(|meta| meta.len())
+ .unwrap_or(0);
+
+ // A read timeout: a stalled connection blocks in `read` with the
+ // cancel flag unreachable, and thirty seconds without a byte means
+ // the download is dead.
+ let agent = ureq::AgentBuilder::new()
+ .timeout_connect(std::time::Duration::from_secs(20))
+ .timeout_read(std::time::Duration::from_secs(30))
+ .build();
+ let mut request = agent.get(url);
+ if already > 0 {
+ request = request.set("Range", &format!("bytes={already}-"));
+ }
+ let response = match request.call() {
+ Ok(response) => response,
+ // Range not satisfiable: everything is already here. Let the
+ // caller's digest check say whether it is the file.
+ Err(ureq::Error::Status(416, _)) if already > 0 => return Ok((already, already)),
+ Err(error) => return Err(format!("{url} did not answer: {error}")),
+ };
+
+ let resumed = response.status() == 206;
+ let remaining = response
+ .header("Content-Length")
+ .and_then(|value| value.parse::<u64>().ok());
+ let (mut received, total) = if resumed {
+ (
+ already,
+ remaining.map_or(estimate.max(already), |rest| already + rest),
+ )
+ } else {
+ (0, remaining.unwrap_or(estimate))
+ };
+ let mut file = if resumed {
+ std::fs::OpenOptions::new().append(true).open(partial)
+ } else {
+ std::fs::File::create(partial)
+ }
+ .map_err(|error| format!("could not write {}: {error}", partial.display()))?;
+
+ let mut reader = response.into_reader();
+ let mut buffer = [0u8; 64 * 1024];
+ let mut reported = received;
+ progress(received, total);
+ loop {
+ if cancel.load(Ordering::Relaxed) {
+ // The partial stays: it is where the next attempt picks up.
+ return Err(cancelled.to_owned());
+ }
+ let read = reader
+ .read(&mut buffer)
+ .map_err(|error| format!("download interrupted: {error}"))?;
+ if read == 0 {
+ break;
+ }
+ file.write_all(&buffer[..read])
+ .map_err(|error| format!("could not write {}: {error}", partial.display()))?;
+ received += read as u64;
+ // Every 2 MB, not every chunk: a progress bar cannot use more.
+ if received - reported >= 2 * 1024 * 1024 {
+ reported = received;
+ progress(received, total);
+ }
+ }
+ file.flush()
+ .map_err(|error| format!("could not write {}: {error}", partial.display()))?;
+ if received == 0 {
+ return Err(format!("{url} came back empty"));
+ }
+ Ok((received, received.max(total)))
}
/// Checks a finished download against the digest the table carries.
@@ -103,12 +335,129 @@ mod tests {
#[test]
fn the_mirror_comes_before_upstream() {
- let [first, second] = sources("model.onnx", "https://elsewhere.example/model.onnx");
+ let list = sources_for(
+ "model.onnx",
+ "https://elsewhere.example/model.onnx",
+ SourcePreference::Auto,
+ "",
+ );
assert_eq!(
- first,
+ list[0],
format!("https://github.com/{REPO}/releases/download/{RELEASE}/model.onnx")
);
- assert_eq!(second, "https://elsewhere.example/model.onnx");
+ assert_eq!(list[1], "https://elsewhere.example/model.onnx");
+ assert_eq!(
+ list.len(),
+ 2,
+ "nothing else holds a file from an unmirrored host"
+ );
+ }
+
+ #[test]
+ fn a_hugging_face_upstream_is_also_offered_through_hf_mirror() {
+ let upstream = "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.bin";
+ let list = sources_for("ggml-tiny.bin", upstream, SourcePreference::Auto, "");
+ assert_eq!(list.len(), 3);
+ assert_eq!(list[1], upstream);
+ assert_eq!(
+ list[2],
+ "https://hf-mirror.com/ggerganov/whisper.cpp/resolve/main/ggml-tiny.bin"
+ );
+ // and first, when that is the preference
+ let list = sources_for("ggml-tiny.bin", upstream, SourcePreference::HfMirror, "");
+ assert!(list[0].starts_with("https://hf-mirror.com/"));
+ assert_eq!(list.len(), 3);
+ assert_eq!(hf_mirror("https://github.com/x/y"), None);
+ }
+
+ #[test]
+ fn a_custom_base_leads_when_asked_and_trails_otherwise() {
+ let list = sources_for(
+ "model.onnx",
+ "https://elsewhere.example/model.onnx",
+ SourcePreference::Custom,
+ "https://models.example/concat",
+ );
+ assert_eq!(list[0], "https://models.example/concat/model.onnx");
+ assert_eq!(list.len(), 3);
+ let list = sources_for(
+ "model.onnx",
+ "https://elsewhere.example/model.onnx",
+ SourcePreference::Upstream,
+ "https://models.example/concat",
+ );
+ assert_eq!(list[0], "https://elsewhere.example/model.onnx");
+ assert_eq!(list[2], "https://models.example/concat/model.onnx");
+ // a custom preference with no base is a plain automatic
+ let list = sources_for("m", "https://u.example/m", SourcePreference::Custom, "");
+ assert_eq!(list.len(), 2);
+ }
+
+ #[test]
+ fn preferences_have_stable_names() {
+ for preference in SourcePreference::ALL {
+ assert_eq!(SourcePreference::parse(preference.name()), preference);
+ }
+ assert_eq!(SourcePreference::parse("nonsense"), SourcePreference::Auto);
+ }
+
+ #[test]
+ fn a_partial_download_is_finished_from_a_range() {
+ use std::io::{Read, Write};
+ // A server that honours Range on one 1 MB file.
+ let body: Vec<u8> = (0..1_048_576u32).map(|i| (i % 251) as u8).collect();
+ let listener = std::net::TcpListener::bind("127.0.0.1:0").expect("a port");
+ let port = listener.local_addr().expect("an address").port();
+ let served = body.clone();
+ std::thread::spawn(move || {
+ for stream in listener.incoming().take(2) {
+ let mut stream = stream.expect("a connection");
+ let mut head = [0u8; 4096];
+ let read = stream.read(&mut head).unwrap_or(0);
+ let head = String::from_utf8_lossy(&head[..read]).to_string();
+ let from = head
+ .lines()
+ .find_map(|line| line.strip_prefix("Range: bytes="))
+ .and_then(|range| range.trim_end_matches('-').parse::<usize>().ok());
+ let (status, slice) = match from {
+ Some(from) if from < served.len() => ("206 Partial Content", &served[from..]),
+ _ => ("200 OK", &served[..]),
+ };
+ let _ = write!(
+ stream,
+ "HTTP/1.1 {status}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
+ slice.len()
+ );
+ let _ = stream.write_all(slice);
+ }
+ });
+ let url = format!("http://127.0.0.1:{port}/model.bin");
+ let partial = std::env::temp_dir().join("concat-models-resume.part");
+ // Half of it is already here, as a dropped connection leaves it.
+ std::fs::write(&partial, &body[..600_000]).expect("a partial");
+ let cancel = std::sync::atomic::AtomicBool::new(false);
+ let mut reports = Vec::new();
+ let (received, total) = download(&url, &partial, 0, &cancel, "stopped", &mut |got, of| {
+ reports.push((got, of))
+ })
+ .expect("the rest arrives");
+ assert_eq!((received, total), (body.len() as u64, body.len() as u64));
+ assert_eq!(
+ std::fs::read(&partial).expect("the file"),
+ body,
+ "the halves join up"
+ );
+ assert_eq!(
+ reports[0],
+ (600_000, body.len() as u64),
+ "progress starts where the partial ended"
+ );
+ // A second request with the file complete: whole again, the
+ // server having nothing to add, is still the file.
+ let (received, _) =
+ download(&url, &partial, 0, &cancel, "stopped", &mut |_, _| {}).expect("again");
+ assert!(received > 0);
+ let _ = std::fs::remove_file(&partial);
}
#[test]
diff --git a/engine/crates/concat-speech/src/lib.rs b/engine/crates/concat-speech/src/lib.rs
index c75d01ca..80c5d723 100644
--- a/engine/crates/concat-speech/src/lib.rs
+++ b/engine/crates/concat-speech/src/lib.rs
@@ -71,8 +71,9 @@ pub(crate) fn fetch_model(
})?;
return Ok(totals);
}
+ // The partial stays for the next source, or the next time:
+ // whichever answers takes up where this one stopped.
Err(error) => {
- let _ = std::fs::remove_file(partial);
if cancel.load(Ordering::Relaxed) {
return Err(error);
}
@@ -83,8 +84,9 @@ pub(crate) fn fetch_model(
Err(last)
}
-/// Streams `url` into `partial`, reporting every couple of megabytes and
-/// stopping when `cancel` is set. Shared by both model downloaders.
+/// Streams `url` into `partial` through the shared downloader - taking
+/// up from whatever of `partial` is already there - reporting every
+/// couple of megabytes and stopping when `cancel` is set.
fn download_to(
url: &str,
partial: &std::path::Path,
@@ -93,60 +95,20 @@ fn download_to(
cancel: &std::sync::atomic::AtomicBool,
progress: &mut dyn FnMut(DownloadProgress),
) -> Result<(u64, u64), String> {
- use std::io::Read;
- use std::sync::atomic::Ordering;
-
- // A read timeout, or a stalled connection blocks in `read` forever
- // with the cancel flag unreachable - the flag is only checked between
- // reads. Thirty seconds without a byte means the download is dead.
- let agent = ureq::AgentBuilder::new()
- .timeout_connect(std::time::Duration::from_secs(20))
- .timeout_read(std::time::Duration::from_secs(30))
- .build();
- let response = agent
- .get(url)
- .call()
- .map_err(|error| format!("download failed: {error}"))?;
- let total = response
- .header("Content-Length")
- .and_then(|value| value.parse::<u64>().ok())
- .unwrap_or(estimate);
-
- let mut file = std::fs::File::create(partial)
- .map_err(|error| format!("could not create {}: {error}", partial.display()))?;
-
- let mut reader = response.into_reader();
- let mut buffer = [0u8; 64 * 1024];
- let mut received: u64 = 0;
- let mut last_report: u64 = 0;
-
- loop {
- if cancel.load(Ordering::Relaxed) {
- drop(file);
- let _ = std::fs::remove_file(partial);
- return Err("download cancelled".to_owned());
- }
- let read = reader
- .read(&mut buffer)
- .map_err(|error| format!("download interrupted: {error}"))?;
- if read == 0 {
- break;
- }
- std::io::Write::write_all(&mut file, &buffer[..read])
- .map_err(|error| format!("could not write model: {error}"))?;
- received += read as u64;
-
- // Every 2 MB, not every chunk: a progress bar cannot use more.
- if received - last_report >= 2 * 1024 * 1024 {
- last_report = received;
+ concat_host::models::download(
+ url,
+ partial,
+ estimate,
+ cancel,
+ "download cancelled",
+ &mut |received, total| {
progress(DownloadProgress {
id: id.to_owned(),
received,
total,
unpacking: false,
done: false,
- });
- }
- }
- Ok((received, received.max(total)))
+ })
+ },
+ )
}
diff --git a/engine/crates/concat-speech/src/transcribe.rs b/engine/crates/concat-speech/src/transcribe.rs
index 55de6901..9031a180 100644
--- a/engine/crates/concat-speech/src/transcribe.rs
+++ b/engine/crates/concat-speech/src/transcribe.rs
@@ -469,10 +469,11 @@ mod tests {
let file = model_archive(model.id);
assert_eq!(file, format!("ggml-{}.bin", model.id));
assert!(model_upstream(model.id).ends_with(&file));
- let [mirror, upstream] = concat_host::models::sources(&file, &model_upstream(model.id));
+ let sources = concat_host::models::sources(&file, &model_upstream(model.id));
+ let (mirror, upstream) = (&sources[0], &sources[1]);
assert!(mirror.contains(concat_host::models::RELEASE));
assert!(mirror.ends_with(&file));
- assert_eq!(upstream, model_upstream(model.id));
+ assert_eq!(*upstream, model_upstream(model.id));
assert!(model.approx_bytes > 0);
}
}
diff --git a/engine/crates/concat-speech/src/tts.rs b/engine/crates/concat-speech/src/tts.rs
index b41cac75..87746146 100644
--- a/engine/crates/concat-speech/src/tts.rs
+++ b/engine/crates/concat-speech/src/tts.rs
@@ -591,10 +591,11 @@ mod tests {
let file = model_archive(model.id);
assert_eq!(file, format!("{}.tar.bz2", model.id));
assert!(model_upstream(model.id).ends_with(&file));
- let [mirror, upstream] = concat_host::models::sources(&file, &model_upstream(model.id));
+ let sources = concat_host::models::sources(&file, &model_upstream(model.id));
+ let (mirror, upstream) = (&sources[0], &sources[1]);
assert!(mirror.contains(concat_host::models::RELEASE));
assert!(mirror.ends_with(&file));
- assert_eq!(upstream, model_upstream(model.id));
+ assert_eq!(*upstream, model_upstream(model.id));
assert!(model.approx_bytes > 0);
}
}
diff --git a/engine/crates/concat/locales/de.json b/engine/crates/concat/locales/de.json
index 411cd7ad..35e4cdd2 100644
--- a/engine/crates/concat/locales/de.json
+++ b/engine/crates/concat/locales/de.json
@@ -126,6 +126,15 @@
"Default title": "Standardtitel",
"Delay": "Verzögerung",
"Delete": "Löschen",
+ "Downloads": "Downloads",
+ "Automatic": "Automatisch",
+ "Concat's mirror": "Concats Spiegel",
+ "Original source": "Ursprüngliche Quelle",
+ "Custom URL": "Eigene URL",
+ "For mainland China": "Für Festlandchina",
+ "Where each model came from": "Wo jedes Modell herkommt",
+ "A mirror of your own": "Ein eigener Spiegel",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Modelle werden geladen, wenn eine Funktion sie zum ersten Mal braucht. Hier sucht der Download zuerst; alle anderen Quellen werden danach trotzdem versucht.",
"Codec": "Codec",
"Plays everywhere": "Läuft überall",
"Half the size": "Halb so groß",
diff --git a/engine/crates/concat/locales/en.json b/engine/crates/concat/locales/en.json
index bcae3230..e4eb0882 100644
--- a/engine/crates/concat/locales/en.json
+++ b/engine/crates/concat/locales/en.json
@@ -13,6 +13,7 @@
"A layer treats everything under it for as long as it runs. Trim it on the timeline to change what it covers.": "A layer treats everything under it for as long as it runs. Trim it on the timeline to change what it covers.",
"A matte: blacks lifted, whites eased down, contrast low, and a soft bloom in the light with cream in it. Airy and flattering.": "A matte: blacks lifted, whites eased down, contrast low, and a soft bloom in the light with cream in it. Airy and flattering.",
"A metallic, modulated voice.": "A metallic, modulated voice.",
+ "A mirror of your own": "A mirror of your own",
"A seventies print: matte blacks and whites, colour faded, greens gone to yellow, a soft vignette.": "A seventies print: matte blacks and whites, colour faded, greens gone to yellow, a soft vignette.",
"A small old speaker: no top end, and a grain to the sound.": "A small old speaker: no top end, and a grain to the sound.",
"A small speaker on a long wave: narrow band, a little crunch.": "A small speaker on a long wave: narrow band, a little crunch.",
@@ -54,6 +55,7 @@
"Auto captions from this clip's sound": "Auto captions from this clip's sound",
"Auto removal": "Auto removal",
"Auto removal keeps what the model finds and drops the rest: a person, or the one thing the picture is of. Custom removal starts from the same mask and takes corrections painted on the monitor: the smart brush keeps the whole thing it touches and the smart eraser removes it, the plain ones do exactly what you paint; Apply ends the painting. Chroma key drops one colour instead; similarity is how far from the colour still counts, softness feathers the edge.": "Auto removal keeps what the model finds and drops the rest: a person, or the one thing the picture is of. Custom removal starts from the same mask and takes corrections painted on the monitor: the smart brush keeps the whole thing it touches and the smart eraser removes it, the plain ones do exactly what you paint; Apply ends the painting. Chroma key drops one colour instead; similarity is how far from the colour still counts, softness feathers the edge.",
+ "Automatic": "Automatic",
"Balanced": "Balanced",
"Barely there: neutral, a gentle curve, a touch more colour, and the reds calmed so a face reads even. What a talking head wants.": "Barely there: neutral, a gentle curve, a touch more colour, and the reds calmed so a face reads even. What a talking head wants.",
"Basic": "Basic",
@@ -127,6 +129,7 @@
"Colour that sings and contrast that bites, with a little edge: the look that reads as a better camera. Skin is held back from the boost.": "Colour that sings and contrast that bites, with a little edge: the look that reads as a better camera. Skin is held back from the boost.",
"Combo": "Combo",
"Concat {0}": "Concat {0}",
+ "Concat's mirror": "Concat's mirror",
"Content": "Content",
"CONTENTS": "CONTENTS",
"Contents": "Contents",
@@ -149,6 +152,7 @@
"Curve": "Curve",
"Custom": "Custom",
"Custom removal": "Custom removal",
+ "Custom URL": "Custom URL",
"Cutout": "Cutout",
"Dancing grain, the texture of film stock.": "Dancing grain, the texture of film stock.",
"Dark": "Dark",
@@ -181,6 +185,7 @@
"Download a transcriber model in Settings › Transcriber first.": "Download a transcriber model in Settings › Transcriber first.",
"Download a voice model in Settings › Speech first": "Download a voice model in Settings › Speech first",
"Download a voice model in Settings › Speech first.": "Download a voice model in Settings › Speech first.",
+ "Downloads": "Downloads",
"Drained colour, a green-cyan cast, a hard toe, and a heavy vignette. For the season.": "Drained colour, a green-cyan cast, a hard toe, and a heavy vignette. For the season.",
"Dread": "Dread",
"Drift": "Drift",
@@ -251,6 +256,7 @@
"Flip vertical": "Flip vertical",
"Folder": "Folder",
"Font": "Font",
+ "For mainland China": "For mainland China",
"Format": "Format",
"Frame": "Frame",
"Frame rate": "Frame rate",
@@ -367,6 +373,7 @@
"Model": "Model",
"Model ready": "Model ready",
"Models": "Models",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.",
"Modify": "Modify",
"Mono": "Mono",
"mono": "mono",
@@ -422,6 +429,7 @@
"Open project": "Open project",
"Open project…": "Open project…",
"Operating system": "Operating system",
+ "Original source": "Original source",
"Other": "Other",
"Out": "Out",
"Outline": "Outline",
@@ -664,6 +672,7 @@
"Warmth": "Warmth",
"Water": "Water",
"Water and sky turned aquamarine and brightened, sand and skin left warm and clean. The beach-day look creators reach for first.": "Water and sky turned aquamarine and brightened, sand and skin left warm and clean. The beach-day look creators reach for first.",
+ "Where each model came from": "Where each model came from",
"Where should the project folder go?": "Where should the project folder go?",
"Whites": "Whites",
"Width": "Width",
diff --git a/engine/crates/concat/locales/es.json b/engine/crates/concat/locales/es.json
index 7fd46594..6fa1239a 100644
--- a/engine/crates/concat/locales/es.json
+++ b/engine/crates/concat/locales/es.json
@@ -126,6 +126,15 @@
"Default title": "Título predeterminado",
"Delay": "Retardo",
"Delete": "Eliminar",
+ "Downloads": "Descargas",
+ "Automatic": "Automático",
+ "Concat's mirror": "Espejo de Concat",
+ "Original source": "Fuente original",
+ "Custom URL": "URL personalizada",
+ "For mainland China": "Para China continental",
+ "Where each model came from": "De donde salió cada modelo",
+ "A mirror of your own": "Un espejo propio",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Los modelos se descargan la primera vez que una función los necesita. Aquí busca primero la descarga; el resto de fuentes se prueban después.",
"Codec": "Códec",
"Plays everywhere": "Se reproduce en todas partes",
"Half the size": "La mitad de tamaño",
diff --git a/engine/crates/concat/locales/fr.json b/engine/crates/concat/locales/fr.json
index 2521571b..33dab71a 100644
--- a/engine/crates/concat/locales/fr.json
+++ b/engine/crates/concat/locales/fr.json
@@ -126,6 +126,15 @@
"Default title": "Titre par défaut",
"Delay": "Délai",
"Delete": "Supprimer",
+ "Downloads": "Téléchargements",
+ "Automatic": "Automatique",
+ "Concat's mirror": "Miroir de Concat",
+ "Original source": "Source d'origine",
+ "Custom URL": "URL personnalisée",
+ "For mainland China": "Pour la Chine continentale",
+ "Where each model came from": "D'où vient chaque modèle",
+ "A mirror of your own": "Un miroir à vous",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Les modèles sont téléchargés la première fois qu'une fonction en a besoin. C'est ici que le téléchargement cherche d'abord ; les autres sources sont essayées ensuite.",
"Codec": "Codec",
"Plays everywhere": "Lisible partout",
"Half the size": "Deux fois plus petit",
diff --git a/engine/crates/concat/locales/hr.json b/engine/crates/concat/locales/hr.json
index e15a03c3..bbdedd5e 100644
--- a/engine/crates/concat/locales/hr.json
+++ b/engine/crates/concat/locales/hr.json
@@ -160,6 +160,15 @@
"Default title": "Zadani naslov",
"Delay": "Kašnjenje",
"Delete": "Obriši",
+ "Downloads": "Preuzimanja",
+ "Automatic": "Automatski",
+ "Concat's mirror": "Concatov zrcalni poslužitelj",
+ "Original source": "Izvorni izvor",
+ "Custom URL": "Vlastiti URL",
+ "For mainland China": "Za kontinentalnu Kinu",
+ "Where each model came from": "Odakle svaki model dolazi",
+ "A mirror of your own": "Vlastito zrcalo",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Modeli se preuzimaju kad ih neka značajka prvi put zatreba. Ovdje preuzimanje traži prvo; ostali izvori se ipak isprobaju nakon toga.",
"Codec": "Kodek",
"Plays everywhere": "Radi svugdje",
"Half the size": "Upola manje",
diff --git a/engine/crates/concat/locales/it.json b/engine/crates/concat/locales/it.json
index dcb8f756..2668bfd7 100644
--- a/engine/crates/concat/locales/it.json
+++ b/engine/crates/concat/locales/it.json
@@ -126,6 +126,15 @@
"Default title": "Titolo predefinito",
"Delay": "Ritardo",
"Delete": "Elimina",
+ "Downloads": "Download",
+ "Automatic": "Automatico",
+ "Concat's mirror": "Mirror di Concat",
+ "Original source": "Fonte originale",
+ "Custom URL": "URL personalizzato",
+ "For mainland China": "Per la Cina continentale",
+ "Where each model came from": "Da dove viene ogni modello",
+ "A mirror of your own": "Un mirror tuo",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "I modelli vengono scaricati la prima volta che una funzione ne ha bisogno. Qui il download cerca per primo; le altre fonti vengono comunque provate dopo.",
"Codec": "Codec",
"Plays everywhere": "Si riproduce ovunque",
"Half the size": "Metà delle dimensioni",
diff --git a/engine/crates/concat/locales/ja.json b/engine/crates/concat/locales/ja.json
index 1360936d..8f221971 100644
--- a/engine/crates/concat/locales/ja.json
+++ b/engine/crates/concat/locales/ja.json
@@ -126,6 +126,15 @@
"Default title": "デフォルトのタイトル",
"Delay": "ディレイ",
"Delete": "削除",
+ "Downloads": "ダウンロード",
+ "Automatic": "自動",
+ "Concat's mirror": "Concat のミラー",
+ "Original source": "元の配布元",
+ "Custom URL": "カスタム URL",
+ "For mainland China": "中国本土向け",
+ "Where each model came from": "各モデルの元の場所",
+ "A mirror of your own": "自分のミラー",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "モデルは機能が初めて必要とした時に取得されます。ここで指定した場所を最初に探し、その後も他の配布元をすべて試します。",
"Codec": "コーデック",
"Plays everywhere": "どこでも再生可能",
"Half the size": "半分のサイズ",
diff --git a/engine/crates/concat/locales/ko.json b/engine/crates/concat/locales/ko.json
index a4b47571..dbd9d969 100644
--- a/engine/crates/concat/locales/ko.json
+++ b/engine/crates/concat/locales/ko.json
@@ -126,6 +126,15 @@
"Default title": "기본 자막",
"Delay": "지연",
"Delete": "삭제",
+ "Downloads": "다운로드",
+ "Automatic": "자동",
+ "Concat's mirror": "Concat 미러",
+ "Original source": "원본 출처",
+ "Custom URL": "사용자 지정 URL",
+ "For mainland China": "중국 본토용",
+ "Where each model came from": "각 모델의 원래 출처",
+ "A mirror of your own": "직접 운영하는 미러",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "모델은 기능이 처음 필요로 할 때 내려받습니다. 여기서 먼저 찾고, 그다음에도 다른 출처를 모두 시도합니다.",
"Codec": "코덱",
"Plays everywhere": "어디서나 재생",
"Half the size": "절반 크기",
diff --git a/engine/crates/concat/locales/pt-BR.json b/engine/crates/concat/locales/pt-BR.json
index 5c45511c..d631440f 100644
--- a/engine/crates/concat/locales/pt-BR.json
+++ b/engine/crates/concat/locales/pt-BR.json
@@ -126,6 +126,15 @@
"Default title": "Título padrão",
"Delay": "Atraso",
"Delete": "Excluir",
+ "Downloads": "Downloads",
+ "Automatic": "Automático",
+ "Concat's mirror": "Espelho do Concat",
+ "Original source": "Fonte original",
+ "Custom URL": "URL personalizada",
+ "For mainland China": "Para a China continental",
+ "Where each model came from": "De onde cada modelo veio",
+ "A mirror of your own": "Um espelho seu",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Os modelos são baixados na primeira vez que um recurso precisa deles. Aqui o download procura primeiro; as outras fontes ainda são tentadas depois.",
"Codec": "Codec",
"Plays everywhere": "Reproduz em qualquer lugar",
"Half the size": "Metade do tamanho",
diff --git a/engine/crates/concat/locales/ru.json b/engine/crates/concat/locales/ru.json
index 8f61a253..15cecf3d 100644
--- a/engine/crates/concat/locales/ru.json
+++ b/engine/crates/concat/locales/ru.json
@@ -126,6 +126,15 @@
"Default title": "Титр по умолчанию",
"Delay": "Задержка",
"Delete": "Удалить",
+ "Downloads": "Загрузки",
+ "Automatic": "Автоматически",
+ "Concat's mirror": "Зеркало Concat",
+ "Original source": "Исходный источник",
+ "Custom URL": "Свой URL",
+ "For mainland China": "Для материкового Китая",
+ "Where each model came from": "Откуда взята каждая модель",
+ "A mirror of your own": "Собственное зеркало",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Модели загружаются, когда функция впервые в них нуждается. Здесь загрузка ищет в первую очередь; остальные источники всё равно проверяются после.",
"Codec": "Кодек",
"Plays everywhere": "Воспроизводится везде",
"Half the size": "Вдвое меньше",
diff --git a/engine/crates/concat/locales/tr.json b/engine/crates/concat/locales/tr.json
index 3b7b61d5..ad032445 100644
--- a/engine/crates/concat/locales/tr.json
+++ b/engine/crates/concat/locales/tr.json
@@ -126,6 +126,15 @@
"Default title": "Varsayılan yazı",
"Delay": "Gecikme",
"Delete": "Sil",
+ "Downloads": "İndirmeler",
+ "Automatic": "Otomatik",
+ "Concat's mirror": "Concat yansısı",
+ "Original source": "Özgün kaynak",
+ "Custom URL": "Özel URL",
+ "For mainland China": "Çin anakarası için",
+ "Where each model came from": "Her modelin geldiği yer",
+ "A mirror of your own": "Kendi yansınız",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "Modeller bir özellik ilk kez ihtiyaç duyduğunda indirilir. İndirme önce buraya bakar; diğer tüm kaynaklar yine de sonra denenir.",
"Codec": "Kodek",
"Plays everywhere": "Her yerde oynatılır",
"Half the size": "Yarı boyut",
diff --git a/engine/crates/concat/locales/zh-Hans.json b/engine/crates/concat/locales/zh-Hans.json
index 26acd1dc..7a4d28a3 100644
--- a/engine/crates/concat/locales/zh-Hans.json
+++ b/engine/crates/concat/locales/zh-Hans.json
@@ -126,6 +126,15 @@
"Default title": "默认字幕",
"Delay": "延迟",
"Delete": "删除",
+ "Downloads": "下载",
+ "Automatic": "自动",
+ "Concat's mirror": "Concat 镜像",
+ "Original source": "原始来源",
+ "Custom URL": "自定义 URL",
+ "For mainland China": "适用于中国大陆",
+ "Where each model came from": "各模型的原始出处",
+ "A mirror of your own": "你自己的镜像",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "模型会在功能首次需要时下载。下载会先从这里查找;之后仍会尝试其他所有来源。",
"Codec": "编码",
"Plays everywhere": "到处都能播放",
"Half the size": "体积减半",
diff --git a/engine/crates/concat/locales/zh-TW.json b/engine/crates/concat/locales/zh-TW.json
index 7c9e9acd..cbe6f331 100644
--- a/engine/crates/concat/locales/zh-TW.json
+++ b/engine/crates/concat/locales/zh-TW.json
@@ -160,6 +160,15 @@
"Default title": "預設標題",
"Delay": "延遲時間",
"Delete": "刪除",
+ "Downloads": "下載",
+ "Automatic": "自動",
+ "Concat's mirror": "Concat 鏡像",
+ "Original source": "原始來源",
+ "Custom URL": "自訂 URL",
+ "For mainland China": "適用於中國大陸",
+ "Where each model came from": "各模型的原始出處",
+ "A mirror of your own": "你自己的鏡像",
+ "Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.": "模型會在功能首次需要時下載。下載會先從這裡尋找;之後仍會嘗試其他所有來源。",
"Codec": "編碼",
"Plays everywhere": "到處都能播放",
"Half the size": "體積減半",
diff --git a/engine/crates/concat/src/lib.rs b/engine/crates/concat/src/lib.rs
index daf8af2a..88f848eb 100644
--- a/engine/crates/concat/src/lib.rs
+++ b/engine/crates/concat/src/lib.rs
@@ -1042,6 +1042,21 @@ pub fn run() -> Result<(), slint::PlatformError> {
let at = state.playhead;
state.seek(at);
}));
+ app.on_settings_download_source_changed(on_window!(|state, index: i32| {
+ use concat_host::models::SourcePreference;
+ let index = (index.max(0) as usize).min(SourcePreference::ALL.len() - 1);
+ state.settings.download_source = index;
+ state.prefs.download_source = Some(SourcePreference::ALL[index].name().to_owned());
+ state.prefs.save(&state.host.dirs);
+ state.apply_download_source();
+ }));
+ app.on_settings_download_base_edited(on_window!(|state, text: SharedString| {
+ let base = text.trim().to_owned();
+ state.settings.download_base = base.clone();
+ state.prefs.download_base = (!base.is_empty()).then_some(base);
+ state.prefs.save(&state.host.dirs);
+ state.apply_download_source();
+ }));
app.on_model_activated(on_window!(|state, id: SharedString| {
state.model_activate(id.as_str());
}));
diff --git a/engine/crates/concat/src/prefs.rs b/engine/crates/concat/src/prefs.rs
index 184cb239..4a8b4cb1 100644
--- a/engine/crates/concat/src/prefs.rs
+++ b/engine/crates/concat/src/prefs.rs
@@ -34,6 +34,11 @@ pub struct Preferences {
/// it is put. Off by default: a click past the last clip lands there, so
/// a clip can be dropped at the playhead beyond everything else.
pub playhead_stops_at_end: bool,
+ /// Where model downloads look first: a `SourcePreference` by name.
+ /// Absent is automatic.
+ pub download_source: Option<String>,
+ /// The base URL a custom download source appends a model's file to.
+ pub download_base: Option<String>,
}
impl Preferences {
diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rs
index bbde64a0..c6da228a 100644
--- a/engine/crates/concat/src/studio.rs
+++ b/engine/crates/concat/src/studio.rs
@@ -319,6 +319,10 @@ pub struct SettingsState {
pub language: usize,
/// The switch that keeps the playhead inside the content.
pub playhead_stops: bool,
+ /// Index into `SourcePreference::ALL`: where model downloads look first.
+ pub download_source: usize,
+ /// The base URL of a custom download source.
+ pub download_base: String,
}
/// The missing media relink dialog state.
@@ -1472,6 +1476,9 @@ impl Studio {
.position(|language| Some(language.code.as_str()) == studio.prefs.locale.as_deref())
.unwrap_or(0);
studio.settings.playhead_stops = studio.prefs.playhead_stops_at_end;
+ studio.settings.download_source = studio.download_source().0;
+ studio.settings.download_base = studio.prefs.download_base.clone().unwrap_or_default();
+ studio.apply_download_source();
studio.refresh_models();
studio
}
@@ -5892,6 +5899,27 @@ impl Studio {
sync(&models.dividers, out.dividers);
}
+ /// The remembered download source: its place in the menu, and itself.
+ pub fn download_source(&self) -> (usize, concat_host::models::SourcePreference) {
+ use concat_host::models::SourcePreference;
+ let preference =
+ SourcePreference::parse(self.prefs.download_source.as_deref().unwrap_or_default());
+ let index = SourcePreference::ALL
+ .iter()
+ .position(|candidate| *candidate == preference)
+ .unwrap_or(0);
+ (index, preference)
+ }
+
+ /// Tells the downloaders where to look first, from the preferences.
+ pub fn apply_download_source(&self) {
+ let (_, preference) = self.download_source();
+ concat_host::models::set_preference(
+ preference,
+ self.prefs.download_base.as_deref().unwrap_or_default(),
+ );
+ }
+
/// Shows the compact dock, or the wide one, keeping whichever is put
/// away whole; see `COMPACT_WIDTH`.
pub fn set_compact(&mut self, compact: bool) {
@@ -6832,6 +6860,8 @@ impl Studio {
tab: self.settings.tab,
language: self.settings.language as i32,
playhead_stops: self.settings.playhead_stops,
+ download_source: self.settings.download_source as i32,
+ download_base: self.settings.download_base.as_str().into(),
disk: {
let installed: Vec<&ModelState> = self
.transcribers
diff --git a/engine/crates/concat/ui/app.slint b/engine/crates/concat/ui/app.slint
index ba635936..1de57571 100644
--- a/engine/crates/concat/ui/app.slint
+++ b/engine/crates/concat/ui/app.slint
@@ -189,6 +189,8 @@ export component App inherits Window {
callback settings-language-changed(index: int);
callback settings-theme-changed(dark: bool);
callback settings-playhead-stops-changed(on: bool);
+ callback settings-download-source-changed(index: int);
+ callback settings-download-base-edited(text: string);
callback model-activated(id: string);
callback model-download(id: string);
callback model-cancel(id: string);
@@ -479,6 +481,8 @@ export component App inherits Window {
language-changed(index) => { root.settings-language-changed(index); }
theme-changed(dark) => { root.settings-theme-changed(dark); }
playhead-stops-changed(on) => { root.settings-playhead-stops-changed(on); }
+ download-source-changed(index) => { root.settings-download-source-changed(index); }
+ download-base-edited(text) => { root.settings-download-base-edited(text); }
model-activated(id) => { root.model-activated(id); }
model-download(id) => { root.model-download(id); }
model-cancel(id) => { root.model-cancel(id); }
diff --git a/engine/crates/concat/ui/dialogs/settings.slint b/engine/crates/concat/ui/dialogs/settings.slint
index e1f8bbaf..a7ac35c0 100644
--- a/engine/crates/concat/ui/dialogs/settings.slint
+++ b/engine/crates/concat/ui/dialogs/settings.slint
@@ -4,7 +4,7 @@
import { I18n } from "../i18n.slint";
import { Theme } from "../theme/theme.slint";
import { Glyph, Icon } from "../icons.slint";
-import { Button, DialogSection, Modal, Progress } from "../primitives/modal.slint";
+import { Button, DialogRow, DialogSection, Field, Modal, Progress } from "../primitives/modal.slint";
import { IconButton } from "../primitives/panel.slint";
import { SegmentedControl } from "../primitives/segmented-control.slint";
import { Select } from "../primitives/select.slint";
@@ -50,6 +50,11 @@ export struct SettingsData {
language: int,
/// the playhead stops at the end of the content
playhead-stops: bool,
+ /// where model downloads look first: automatic, Concat's mirror,
+ /// hf-mirror.com, the original source, a custom URL
+ download-source: int,
+ /// the base URL of a custom source
+ download-base: string,
/// "3 installed · 612 MB on disk"
disk: string,
version: string,
@@ -345,6 +350,8 @@ export component SettingsDialog inherits Modal {
/// on, which is the whole reason it moved in here.
callback theme-changed(dark: bool);
callback playhead-stops-changed(on: bool);
+ callback download-source-changed(index: int);
+ callback download-base-edited(text: string);
callback model-activated(id: string);
callback model-download(id: string);
callback model-cancel(id: string);
@@ -481,6 +488,43 @@ export component SettingsDialog inherits Modal {
}
}
}
+
+ // The models are open weights from elsewhere, mirrored so
+ // they stay reachable; where a download looks first is a
+ // matter of where you are. Every source is still tried.
+ DialogSection {
+ title: I18n.t("Downloads");
+ hint: I18n.t("Models are fetched the first time a feature needs one. This is where the download looks first; every other source is still tried after it.");
+
+ DialogRow {
+ label: I18n.t("Source");
+ Select {
+ current: root.data.download-source;
+ options: [
+ I18n.t("Automatic"),
+ I18n.t("Concat's mirror"),
+ "hf-mirror.com",
+ I18n.t("Original source"),
+ I18n.t("Custom URL"),
+ ];
+ details: [
+ "",
+ "github.com",
+ I18n.t("For mainland China"),
+ I18n.t("Where each model came from"),
+ I18n.t("A mirror of your own"),
+ ];
+ changed(index) => { root.download-source-changed(index); }
+ }
+ }
+
+ if root.data.download-source == 4: Field {
+ value: root.data.download-base;
+ placeholder: "https://models.example.com/concat";
+ technical: true;
+ edited(text) => { root.download-base-edited(text); }
+ }
+ }
}
// Read straight off the Theme global rather than through
diff --git a/scripts/models.py b/scripts/models.py
index 07e89341..4b31eb67 100755
--- a/scripts/models.py
+++ b/scripts/models.py
@@ -56,6 +56,14 @@ def table() -> dict:
return tomllib.loads(MANIFEST.read_text(encoding="utf-8"))
+def hf_mirror(url: str) -> str | None:
+ """`url` through hf-mirror.com, for a Hugging Face URL; None otherwise."""
+ for host in ("https://huggingface.co/", "https://hf.co/"):
+ if url.startswith(host):
+ return "https://hf-mirror.com/" + url[len(host):]
+ return None
+
+
def asset_url(release: str, file: str) -> str:
return f"https://github.com/{REPO}/releases/download/{release}/{file}"
@@ -297,6 +305,18 @@ def release_manifest(version: str, tag: str, bundles: pathlib.Path | None) -> di
"licence": model["licence"],
"url": asset_url(release, model["file"]),
"upstream": model["upstream"],
+ # Every place the file can be fetched from, best first: the
+ # app's own order, for anything that reads this instead of the
+ # app. hf-mirror.com carries whatever Hugging Face does.
+ "sources": [
+ url
+ for url in [
+ asset_url(release, model["file"]),
+ model["upstream"],
+ hf_mirror(model["upstream"]),
+ ]
+ if url
+ ],
}
return {