-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b37f26b
commit 88198fc
Showing
5 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "gradio" | ||
version = "0.2.2" | ||
version = "0.2.3" | ||
edition = "2021" | ||
authors = ["Jacob Lin <[email protected]>"] | ||
description = "Gradio Client in Rust." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use gradio::{Client, ClientOptions, PredictionInput}; | ||
|
||
fn main() { | ||
let client = Client::new_sync("gradio/hello_world", ClientOptions::default()).unwrap(); | ||
|
||
let output = client | ||
.predict_sync("/predict", vec![PredictionInput::from_value("Jacob")]) | ||
.unwrap(); | ||
|
||
println!( | ||
"Output: {}", | ||
output[0].clone().as_value().unwrap().as_str().unwrap() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::client::{Client, ClientOptions}; | ||
use crate::data::{GradioFileData, PredictionInput, PredictionOutput}; | ||
use anyhow::Result; | ||
use std::path::Path; | ||
use tokio::runtime::Runtime; | ||
|
||
impl Client { | ||
pub fn new_sync(app_reference: &str, options: ClientOptions) -> Result<Self> { | ||
let rt = Runtime::new()?; | ||
let client = rt.block_on(Client::new(app_reference, options))?; | ||
Ok(client) | ||
} | ||
|
||
pub fn predict_sync( | ||
&self, | ||
path: &str, | ||
inputs: Vec<PredictionInput>, | ||
) -> Result<Vec<PredictionOutput>> { | ||
let rt = Runtime::new()?; | ||
let output = rt.block_on(self.predict(path, inputs))?; | ||
Ok(output) | ||
} | ||
} | ||
|
||
impl GradioFileData { | ||
pub fn download_sync(&self, http_client: Option<reqwest::Client>) -> Result<bytes::Bytes> { | ||
let rt = Runtime::new()?; | ||
let bytes = rt.block_on(self.download(http_client))?; | ||
Ok(bytes) | ||
} | ||
|
||
pub fn save_to_path_sync( | ||
&self, | ||
path: impl AsRef<Path>, | ||
http_client: Option<reqwest::Client>, | ||
) -> Result<()> { | ||
let rt = Runtime::new()?; | ||
rt.block_on(self.save_to_path(path, http_client))?; | ||
Ok(()) | ||
} | ||
} |