Model Weight Queries has to be worked on categories and types tests written.

This commit is contained in:
Michael Chung committed 2023-11-17 23:39:55 -05:00
1 parent c920ae5286
commit 55344fc6dd
10 files changed
+262 -2

No files matched your search

Binary file not shown.
+1 -1
View File
@@ -14,7 +14,7 @@ pub mod user_ratings;
pub mod voice_conversion_models;
pub mod voice_conversion_results;
pub mod zs_voices;
pub mod model_weights;
// ===== Sqlite =====
pub mod tts_render_tasks;
pub mod web_rendition_targets;
@@ -0,0 +1,2 @@
pub mod weights_types;
pub mod weights_category;
@@ -0,0 +1,82 @@
use std::collections::BTreeSet;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
#[cfg_attr(test, derive(EnumIter, EnumCount))]
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize,Debug)]
pub enum WeightsCategory {
#[serde(rename = "image_generation")]
ImageGeneration,
#[serde(rename = "text_to_speech")]
TextToSpeech,
#[serde(rename = "vocoder")]
Vocoder,
#[serde(rename = "voice_conversion")]
VoiceConversion,
}
impl WeightsCategory {
pub fn to_str(&self) -> &'static str {
match self {
Self::ImageGeneration => "image_generation",
Self::TextToSpeech => "text_to_speech",
Self::Vocoder => "vocoder",
Self::VoiceConversion => "voice_conversion",
}
}
pub fn from_str(value: &str) -> Result<Self, String> {
match value {
"image_generation" => Ok(Self::ImageGeneration),
"text_to_speech" => Ok(Self::TextToSpeech),
"vocoder" => Ok(Self::Vocoder),
"voice_conversion" => Ok(Self::VoiceConversion),
_ => Err(format!("invalid value: {:?}", value)),
}
}
pub fn all_variants() -> BTreeSet<Self> {
BTreeSet::from([
Self::ImageGeneration,
Self::TextToSpeech,
Self::Vocoder,
Self::VoiceConversion,
])
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_to_str() {
assert_eq!(WeightsCategory::ImageGeneration.to_str(), "image_generation");
assert_eq!(WeightsCategory::TextToSpeech.to_str(), "text_to_speech");
assert_eq!(WeightsCategory::Vocoder.to_str(), "vocoder");
assert_eq!(WeightsCategory::VoiceConversion.to_str(), "voice_conversion");
}
#[test]
fn test_from_str() {
assert_eq!(WeightsCategory::from_str("image_generation").unwrap(), WeightsCategory::ImageGeneration);
assert_eq!(WeightsCategory::from_str("text_to_speech").unwrap(), WeightsCategory::TextToSpeech);
assert_eq!(WeightsCategory::from_str("vocoder").unwrap(), WeightsCategory::Vocoder);
assert_eq!(WeightsCategory::from_str("voice_conversion").unwrap(), WeightsCategory::VoiceConversion);
assert!(WeightsCategory::from_str("invalid").is_err());
}
#[test]
fn test_all_variants() {
let variants = WeightsCategory::all_variants();
assert_eq!(variants.len(), 4);
assert!(variants.contains(&WeightsCategory::ImageGeneration));
assert!(variants.contains(&WeightsCategory::TextToSpeech));
assert!(variants.contains(&WeightsCategory::Vocoder));
assert!(variants.contains(&WeightsCategory::VoiceConversion));
}
}
@@ -0,0 +1,105 @@
use std::collections::BTreeSet;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
#[cfg_attr(test, derive(EnumIter, EnumCount))]
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize,Debug)]
pub enum WeightsType {
#[serde(rename = "hifigan_tt2")]
HifiganTacotron2,
#[serde(rename = "rvc_v2")]
RvcV2,
#[serde(rename = "sd_1.5")]
StableDiffusion15,
#[serde(rename = "sdxl")]
StableDiffusionXL,
#[serde(rename = "so_vits_svc")]
SoVitsSvc,
#[serde(rename = "tt2")]
Tacotron2,
#[serde(rename = "loRA")]
LoRA,
}
impl WeightsType {
pub fn to_str(&self) -> &'static str {
match self {
Self::HifiganTacotron2 => "hifigan_tt2",
Self::RvcV2 => "rvc_v2",
Self::StableDiffusion15 => "sd_1.5",
Self::StableDiffusionXL => "sdxl",
Self::SoVitsSvc => "so_vits_svc",
Self::Tacotron2 => "tt2",
Self::LoRA => "loRA",
}
}
pub fn from_str(value: &str) -> Result<Self, String> {
match value {
"hifigan_tt2" => Ok(Self::HifiganTacotron2),
"rvc_v2" => Ok(Self::RvcV2),
"sd_1.5" => Ok(Self::StableDiffusion15),
"sdxl" => Ok(Self::StableDiffusionXL),
"so_vits_svc" => Ok(Self::SoVitsSvc),
"tt2" => Ok(Self::Tacotron2),
"loRA" => Ok(Self::LoRA),
_ => Err(format!("invalid value: {:?}", value)),
}
}
pub fn all_variants() -> BTreeSet<Self> {
BTreeSet::from([
Self::HifiganTacotron2,
Self::RvcV2,
Self::StableDiffusion15,
Self::StableDiffusionXL,
Self::SoVitsSvc,
Self::Tacotron2,
Self::LoRA,
])
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_to_str() {
assert_eq!(WeightsType::HifiganTacotron2.to_str(), "hifigan_tt2");
assert_eq!(WeightsType::RvcV2.to_str(), "rvc_v2");
assert_eq!(WeightsType::StableDiffusion15.to_str(), "sd_1.5");
assert_eq!(WeightsType::StableDiffusionXL.to_str(), "sdxl");
assert_eq!(WeightsType::SoVitsSvc.to_str(), "so_vits_svc");
assert_eq!(WeightsType::Tacotron2.to_str(), "tt2");
assert_eq!(WeightsType::LoRA.to_str(), "loRA");
}
#[test]
fn test_from_str() {
assert_eq!(WeightsType::from_str("hifigan_tt2").unwrap(), WeightsType::HifiganTacotron2);
assert_eq!(WeightsType::from_str("rvc_v2").unwrap(), WeightsType::RvcV2);
assert_eq!(WeightsType::from_str("sd_1.5").unwrap(), WeightsType::StableDiffusion15);
assert_eq!(WeightsType::from_str("sdxl").unwrap(), WeightsType::StableDiffusionXL);
assert_eq!(WeightsType::from_str("so_vits_svc").unwrap(), WeightsType::SoVitsSvc);
assert_eq!(WeightsType::from_str("tt2").unwrap(), WeightsType::Tacotron2);
assert_eq!(WeightsType::from_str("loRA").unwrap(), WeightsType::LoRA);
assert!(WeightsType::from_str("invalid").is_err());
}
#[test]
fn test_all_variants() {
let variants = WeightsType::all_variants();
assert_eq!(variants.len(), 7);
assert!(variants.contains(&WeightsType::HifiganTacotron2));
assert!(variants.contains(&WeightsType::RvcV2));
assert!(variants.contains(&WeightsType::StableDiffusion15));
assert!(variants.contains(&WeightsType::StableDiffusionXL));
assert!(variants.contains(&WeightsType::SoVitsSvc));
assert!(variants.contains(&WeightsType::Tacotron2));
assert!(variants.contains(&WeightsType::LoRA));
}
}
@@ -1,3 +1,4 @@
pub mod users;
pub mod voice_conversion;
pub mod zero_shot_tts;
pub mod zero_shot_tts;
pub mod model_weights;
@@ -0,0 +1,65 @@
use storyteller_root::get_storyteller_rust_root;
use tokens::tokens::users::UserToken;
use log::info;
use sqlx::{MySql, Pool};
use enums::by_table::voice_conversion_models::voice_conversion_model_type::VoiceConversionModelType;
use errors::{anyhow, AnyhowResult};
use mysql_queries::queries::users::user::get_user_token_by_username::get_user_token_by_username;
use mysql_queries::queries::voice_conversion::models::insert_voice_conversion_model_from_download_job::{insert_voice_conversion_model_from_download_job, InsertVoiceConversionModelArgs};
use crate::seeding::users::HANASHI_USERNAME;
pub async fn seed_weights(mysql_pool: &Pool<MySql>) -> AnyhowResult<()> {
info!("Seeding weights...");
// let user_token = match get_user_token_by_username(HANASHI_USERNAME, mysql_pool).await? {
// None => { return Err(anyhow!("could not find user hanashi")) }
// Some(token) => token,
// };
// let rvc_models = [
// // NB: The bucket hashes here are already uploaded to the development Google Cloud Storage
// // bucket and should be usable if you have the development secrets on your machine.
// ("Eric Cartman", "4t9d3y4ve807q69t806pw352dx82h83dzf52bfrp9s9z63gqsxgyezxf8fzdn9yn", true),
// ("Stewie", "bvfe3zwvqnrv64rrtvva1f3r2p2k5tpznfejbh90r353brzqfkveytzyt4cy73hs", true),
// ("Yoda", "cqbcbjsbdy77s4g525nrs791s035b13wew7rp6pep49sx0xr8pqr5af5sseqtkq7", false),
// ];
// for (title, private_bucket_hash, has_index_file) in rvc_models {
// create_rvc_model(title, private_bucket_hash, has_index_file, &user_token, mysql_pool).await?;
// }
Ok(())
}
async fn create_rvc_model(
title: &str,
private_bucket_hash: &str,
has_index_file: bool,
creator_user_token: &UserToken,
mysql_pool: &Pool<MySql>,
) -> AnyhowResult<()> {
// info!("Creating voice conversion record");
// insert_voice_conversion_model_from_download_job(InsertVoiceConversionModelArgs {
// model_type: VoiceConversionModelType::RvcV2,
// title,
// original_download_url: "https://example.com",
// original_filename: "unknown.zip",
// file_size_bytes: 1234,
// creator_user_token: creator_user_token.as_str(),
// creator_ip_address: "127.0.0.1",
// creator_set_visibility: Default::default(),
// has_index_file,
// private_bucket_hash,
// private_bucket_object_name: "unused",
// mysql_pool,
// }).await?;
Ok(())
}
@@ -22,3 +22,4 @@ pub mod voice_clone_requests;
pub mod voice_conversion;
pub mod voice_designer;
pub mod w2l;
pub mod model_weights;
@@ -0,0 +1,3 @@
use sqlx::{MySql, Pool};
use enums::by_table::generic_synthetic_ids::id_category::IdCategory;
@@ -0,0 +1 @@
pub mod create_weight;