PredictionOutput

Enum PredictionOutput 

Source
pub enum PredictionOutput {
    File(GradioFileData),
    Value(Value),
}

Variants§

Implementations§

Source§

impl PredictionOutput

Source

pub fn is_file(&self) -> bool

Source

pub fn is_value(&self) -> bool

Source

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
Hide additional 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}
Source

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
Hide additional 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

Source§

fn clone(&self) -> PredictionOutput

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PredictionOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PredictionOutput

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PredictionOutput

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,