pub enum PredictionOutput {
File(GradioFileData),
Value(Value),
}Variants§
File(GradioFileData)
Value(Value)
Implementations§
Source§impl PredictionOutput
impl PredictionOutput
pub fn is_file(&self) -> bool
pub fn is_value(&self) -> bool
Sourcepub fn as_file(self) -> Result<GradioFileData>
pub fn as_file(self) -> Result<GradioFileData>
Examples found in repository?
examples/parler.rs (line 33)
4async fn main() {
5 if std::env::args().len() < 2 {
6 println!("Please provide the content as an argument");
7 std::process::exit(1);
8 }
9 let args: Vec<String> = std::env::args().collect();
10 let content = &args[1];
11 let description = if args.len() > 2 {
12 &args[2]
13 } else {
14 "Talia speaks high quality audio."
15 };
16
17 let client = Client::new("parler-tts/parler-tts-expresso", ClientOptions::default())
18 .await
19 .unwrap();
20
21 let output = client
22 .predict(
23 "/gen_tts",
24 vec![
25 PredictionInput::from_value(content),
26 PredictionInput::from_value(description),
27 ],
28 )
29 .await
30 .unwrap();
31 println!(
32 "Generated audio: {}",
33 output[0].clone().as_file().unwrap().url.unwrap()
34 );
35}More examples
examples/vocal-separation.rs (line 29)
4async fn main() {
5 if std::env::args().len() < 2 {
6 println!("Please provide an audio file path as an argument");
7 std::process::exit(1);
8 }
9 let args: Vec<String> = std::env::args().collect();
10 let file_path = &args[1];
11 println!("File: {}", file_path);
12
13 let client = Client::new("JacobLinCool/vocal-separation", ClientOptions::default())
14 .await
15 .unwrap();
16
17 let output = client
18 .predict(
19 "/separate",
20 vec![
21 PredictionInput::from_file(file_path),
22 PredictionInput::from_value("BS-RoFormer"),
23 ],
24 )
25 .await
26 .unwrap();
27 println!(
28 "Vocals: {}",
29 output[0].clone().as_file().unwrap().url.unwrap()
30 );
31 println!(
32 "Background: {}",
33 output[1].clone().as_file().unwrap().url.unwrap()
34 );
35}examples/sd3.rs (line 65)
5async fn main() {
6 if std::env::args().len() < 2 {
7 println!("Please provide the prompt as an argument");
8 std::process::exit(1);
9 }
10 let args: Vec<String> = std::env::args().collect();
11 let prompt = &args[1];
12
13 let client = Client::new(
14 "stabilityai/stable-diffusion-3-medium",
15 ClientOptions::default(),
16 )
17 .await
18 .unwrap();
19
20 let mut prediction = client
21 .submit(
22 "/infer",
23 vec![
24 PredictionInput::from_value(prompt),
25 PredictionInput::from_value(""), // negative_prompt
26 PredictionInput::from_value(0), // seed
27 PredictionInput::from_value(true), // randomize_seed
28 PredictionInput::from_value(1024), // width
29 PredictionInput::from_value(1024), // height
30 PredictionInput::from_value(5), // guidance_scale
31 PredictionInput::from_value(28), // num_inference_steps
32 ],
33 )
34 .await
35 .unwrap();
36
37 while let Some(event) = prediction.next().await {
38 let event = event.unwrap();
39 match event {
40 gradio::structs::QueueDataMessage::Estimation {
41 rank, queue_size, ..
42 } => {
43 println!("Queueing: {}/{}", rank + 1, queue_size);
44 }
45 gradio::structs::QueueDataMessage::Progress { progress_data, .. } => {
46 if progress_data.is_none() {
47 continue;
48 }
49 let progress_data = progress_data.unwrap();
50 if !progress_data.is_empty() {
51 let progress_data = &progress_data[0];
52 println!(
53 "Processing: {}/{} {}",
54 progress_data.index + 1,
55 progress_data.length.unwrap(),
56 progress_data.unit
57 );
58 }
59 }
60 gradio::structs::QueueDataMessage::ProcessCompleted { output, .. } => {
61 let output: Vec<PredictionOutput> = output.try_into().unwrap();
62
63 println!(
64 "Generated Image: {}",
65 output[0].clone().as_file().unwrap().url.unwrap()
66 );
67 println!(
68 "Seed: {}",
69 output[1].clone().as_value().unwrap().as_i64().unwrap()
70 );
71 break;
72 }
73 _ => {}
74 }
75 }
76}Sourcepub fn as_value(self) -> Result<Value>
pub fn as_value(self) -> Result<Value>
Examples found in repository?
examples/hello-sync.rs (line 12)
3fn main() {
4 let client = Client::new_sync("gradio/hello_world", ClientOptions::default()).unwrap();
5
6 let output = client
7 .predict_sync("/predict", vec![PredictionInput::from_value("Jacob")])
8 .unwrap();
9
10 println!(
11 "Output: {}",
12 output[0].clone().as_value().unwrap().as_str().unwrap()
13 );
14}More examples
examples/hello.rs (line 15)
4async fn main() {
5 let client = Client::new("gradio/hello_world", ClientOptions::default())
6 .await
7 .unwrap();
8
9 let output = client
10 .predict("/predict", vec![PredictionInput::from_value("Jacob")])
11 .await
12 .unwrap();
13 println!(
14 "Output: {}",
15 output[0].clone().as_value().unwrap().as_str().unwrap()
16 );
17}examples/whisper.rs (line 29)
4async fn main() {
5 if std::env::args().len() < 2 {
6 println!("Please provide an audio file path as an argument");
7 std::process::exit(1);
8 }
9 let args: Vec<String> = std::env::args().collect();
10 let file_path = &args[1];
11 println!("File: {}", file_path);
12
13 let client = Client::new("hf-audio/whisper-large-v3", ClientOptions::default())
14 .await
15 .unwrap();
16
17 let output = client
18 .predict(
19 "/predict",
20 vec![
21 PredictionInput::from_file(file_path),
22 PredictionInput::from_value("transcribe"),
23 ],
24 )
25 .await
26 .unwrap();
27 println!(
28 "Output: {}",
29 output[0].clone().as_value().unwrap().as_str().unwrap()
30 );
31}examples/whisper-turbo.rs (line 30)
4async fn main() {
5 if std::env::args().len() < 2 {
6 println!("Please provide an audio file path as an argument");
7 std::process::exit(1);
8 }
9 let args: Vec<String> = std::env::args().collect();
10 let file_path = &args[1];
11 println!("File: {}", file_path);
12
13 // Gradio v5
14 let client = Client::new("hf-audio/whisper-large-v3-turbo", ClientOptions::default())
15 .await
16 .unwrap();
17
18 let output = client
19 .predict(
20 "/predict",
21 vec![
22 PredictionInput::from_file(file_path),
23 PredictionInput::from_value("transcribe"),
24 ],
25 )
26 .await
27 .unwrap();
28 println!(
29 "Output: {}",
30 output[0].clone().as_value().unwrap().as_str().unwrap()
31 );
32}examples/sd3.rs (line 69)
5async fn main() {
6 if std::env::args().len() < 2 {
7 println!("Please provide the prompt as an argument");
8 std::process::exit(1);
9 }
10 let args: Vec<String> = std::env::args().collect();
11 let prompt = &args[1];
12
13 let client = Client::new(
14 "stabilityai/stable-diffusion-3-medium",
15 ClientOptions::default(),
16 )
17 .await
18 .unwrap();
19
20 let mut prediction = client
21 .submit(
22 "/infer",
23 vec![
24 PredictionInput::from_value(prompt),
25 PredictionInput::from_value(""), // negative_prompt
26 PredictionInput::from_value(0), // seed
27 PredictionInput::from_value(true), // randomize_seed
28 PredictionInput::from_value(1024), // width
29 PredictionInput::from_value(1024), // height
30 PredictionInput::from_value(5), // guidance_scale
31 PredictionInput::from_value(28), // num_inference_steps
32 ],
33 )
34 .await
35 .unwrap();
36
37 while let Some(event) = prediction.next().await {
38 let event = event.unwrap();
39 match event {
40 gradio::structs::QueueDataMessage::Estimation {
41 rank, queue_size, ..
42 } => {
43 println!("Queueing: {}/{}", rank + 1, queue_size);
44 }
45 gradio::structs::QueueDataMessage::Progress { progress_data, .. } => {
46 if progress_data.is_none() {
47 continue;
48 }
49 let progress_data = progress_data.unwrap();
50 if !progress_data.is_empty() {
51 let progress_data = &progress_data[0];
52 println!(
53 "Processing: {}/{} {}",
54 progress_data.index + 1,
55 progress_data.length.unwrap(),
56 progress_data.unit
57 );
58 }
59 }
60 gradio::structs::QueueDataMessage::ProcessCompleted { output, .. } => {
61 let output: Vec<PredictionOutput> = output.try_into().unwrap();
62
63 println!(
64 "Generated Image: {}",
65 output[0].clone().as_file().unwrap().url.unwrap()
66 );
67 println!(
68 "Seed: {}",
69 output[1].clone().as_value().unwrap().as_i64().unwrap()
70 );
71 break;
72 }
73 _ => {}
74 }
75 }
76}Trait Implementations§
Source§impl Clone for PredictionOutput
impl Clone for PredictionOutput
Source§fn clone(&self) -> PredictionOutput
fn clone(&self) -> PredictionOutput
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PredictionOutput
impl Debug for PredictionOutput
Source§impl<'de> Deserialize<'de> for PredictionOutput
impl<'de> Deserialize<'de> for PredictionOutput
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for PredictionOutput
impl RefUnwindSafe for PredictionOutput
impl Send for PredictionOutput
impl Sync for PredictionOutput
impl Unpin for PredictionOutput
impl UnwindSafe for PredictionOutput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more