mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-13 13:22:57 +00:00
JSON early access endpoint
This commit is contained in:
1 parent
767d7a78e8
commit
82a47f5d27
5 files changed
+24
-16
No files matched your search
@@ -594,13 +594,6 @@ model_pipeline = "ArpabetGlowTtsMelgan"
|
||||
glow_tts = "glow-tts_neil_degrasse_tyson_ljstx_2020.07.05_expr-1_chkpt-2482.torchjit"
|
||||
melgan = "melgan_manyvoice2.0_2020-07-08_12d5838_9330.torchjit"
|
||||
|
||||
[[speakers]]
|
||||
name = "Samuel L. Jackson"
|
||||
slug = "samuel-l-jackson"
|
||||
model_pipeline = "ArpabetGlowTtsMelgan"
|
||||
glow_tts = "glow-tts_samuel_l_jackson_ljstx_2020.07.05_expr-1_chkpt-2444.torchjit"
|
||||
melgan = "melgan_manyvoice2.0_2020-07-08_12d5838_9330.torchjit"
|
||||
|
||||
[[speakers]]
|
||||
name = "Bill Nye"
|
||||
slug = "bill-nye"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use anyhow::anyhow;
|
||||
use crate::AnyhowResult;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
@@ -19,6 +20,7 @@ pub struct BonusEndpoint {
|
||||
}
|
||||
|
||||
/// Mapping of all the voices.
|
||||
#[derive(Clone)]
|
||||
pub struct BonusEndpointMappings {
|
||||
pub url_slug_to_voices: HashMap<String, Vec<String>>
|
||||
}
|
||||
@@ -34,6 +36,9 @@ impl BonusEndpoints {
|
||||
let mut mappings = HashMap::new();
|
||||
|
||||
for endpoint in self.bonus_endpoints.iter() {
|
||||
if mappings.contains_key(&endpoint.http_endpoint) {
|
||||
return Err(anyhow!("Endpoint already present in mappings: {}", &endpoint.http_endpoint));
|
||||
}
|
||||
mappings.insert(endpoint.http_endpoint.to_string(), endpoint.voices.clone());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +1,33 @@
|
||||
use actix_web::web::{
|
||||
Data,
|
||||
Json,
|
||||
Path,
|
||||
};
|
||||
use actix_web::{
|
||||
HttpRequest,
|
||||
get,
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
use crate::AppState;
|
||||
use crate::endpoints::speakers::SpeakersResult;
|
||||
use crate::model::model_config::Speaker;
|
||||
use std::sync::Arc;
|
||||
|
||||
/*#[get("/access/{key}")]
|
||||
#[get("/access/{key}")]
|
||||
pub async fn get_dynamic_early_access_speakers(
|
||||
_request: HttpRequest,
|
||||
path_data: web::Path<(String,)>,
|
||||
path_data: Path<(String,)>,
|
||||
app_state: Data<Arc<AppState>>
|
||||
) -> std::io::Result<Json<SpeakersResult>> {
|
||||
|
||||
println!("GET /access");
|
||||
|
||||
let url_key = path_data.into_inner().0;
|
||||
let app_state = app_state.into_inner();
|
||||
let mappings = &app_state.bonus_endpoint_mappings;
|
||||
|
||||
let early_access_voices =
|
||||
app_state.model_configs.early_access_voices
|
||||
mappings.url_slug_to_voices.get(&url_key)
|
||||
.as_ref()
|
||||
.map_or(Vec::new(), |list| list.clone());
|
||||
.map_or(Vec::new(), |list| list.to_vec());
|
||||
|
||||
let mut early_access_speakers : Vec<Speaker> = Vec::new();
|
||||
|
||||
@@ -39,4 +41,3 @@ pub async fn get_dynamic_early_access_speakers(
|
||||
speakers: early_access_speakers,
|
||||
}))
|
||||
}
|
||||
*/
|
||||
@@ -13,7 +13,7 @@ use crate::model::model_config::Speaker;
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
pub struct SpeakersResult {
|
||||
speakers: Vec<Speaker>,
|
||||
pub speakers: Vec<Speaker>,
|
||||
}
|
||||
|
||||
#[get("/speakers")]
|
||||
|
||||
@@ -40,7 +40,9 @@ use actix::{Addr, SyncArbiter, Context};
|
||||
use arpabet::Arpabet;
|
||||
use arpabet::load_cmudict;
|
||||
use arpabet::load_from_file as arpabet_load_from_file;
|
||||
use crate::bonus_voices::config::BonusEndpointMappings;
|
||||
use crate::bonus_voices::config::BonusEndpoints;
|
||||
use crate::bonus_voices::endpoints::get_dynamic_early_access_speakers;
|
||||
use crate::database::connector::DatabaseConnector;
|
||||
use crate::database::sentence_recorder::SentenceRecorder;
|
||||
use crate::endpoints::helpers::stats_recorder::StatsRecorder;
|
||||
@@ -136,6 +138,9 @@ pub struct AppState {
|
||||
pub rate_limiter: Box<dyn RateLimiter>,
|
||||
pub stats_recorder: StatsRecorder,
|
||||
pub allow_model_reload: bool,
|
||||
|
||||
// Bonus voices for "early access" and rewards.
|
||||
pub bonus_endpoint_mappings: BonusEndpointMappings,
|
||||
}
|
||||
|
||||
/** Startup parameters for the server. */
|
||||
@@ -240,6 +245,8 @@ pub fn main() -> AnyhowResult<()> {
|
||||
|
||||
info!("Bonus endpoints: {:?}", bonus_endpoints);
|
||||
|
||||
let bonus_endpoint_mappings = bonus_endpoints.to_mappings()?;
|
||||
|
||||
let model_cache = ModelCache::new(&model_configs.model_locations);
|
||||
|
||||
let rate_limiter : Box<dyn RateLimiter> = if limiter_enabled {
|
||||
@@ -317,6 +324,7 @@ pub fn main() -> AnyhowResult<()> {
|
||||
rate_limiter,
|
||||
stats_recorder,
|
||||
allow_model_reload,
|
||||
bonus_endpoint_mappings,
|
||||
};
|
||||
|
||||
let server_args = ServerArgs {
|
||||
@@ -418,6 +426,7 @@ async fn run_server(app_state: AppState, server_args: ServerArgs) -> std::io::Re
|
||||
.service(get_service_settings)
|
||||
.service(get_speakers)
|
||||
.service(get_early_access_speakers)
|
||||
.service(get_dynamic_early_access_speakers)
|
||||
.service(get_words)
|
||||
.app_data(arc.clone())
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user