Crates.io | huggingface_inference_rs |
lib.rs | huggingface_inference_rs |
version | 0.5.0 |
source | src |
created_at | 2023-06-28 13:39:16.160904 |
updated_at | 2023-07-03 09:51:20.980212 |
description | this package is a small wrapper for hugging face Inference API |
homepage | |
repository | https://github.com/Yvonne-Aizawa/hugging-face-inference-api-wrapper |
max_upload_size | |
id | 902112 |
size | 48,325 |
I use the hugging face inference api. i wrote a wrapper for this. currently it can detect emotions in text, detect places,people in text and answer a question about a text
[dependencies]
huggingface_inference_rs = "0.3.0"
tokio = { version = "1.28.2", features = ["rt-multi-thread", "macros"] }
#[tokio::main]
async fn main() {
let mut config = hg_api::Config::default();
config.key = "hf_key".to_string();
let client = hg_api::Client::new(config);
let test_string = "This is the story of a man named Stanley. Stanley worked for a company in a big building where he was Employee #427. Employee #427's job was simple: he sat at his desk in Room 427 and he pushed buttons on a keyboard. ".to_string();
let emotions = client.get_emotions(test_string.to_owned()).await;
let classifications = client.get_classifications(test_string.to_owned()).await;
let answer = client
.get_question(
test_string,
"what employee number does stanly have?".to_string(),
)
.await;
match emotions {
Ok(emotions) => {
for emotion in emotions {
println!("{},{}", emotion.label, emotion.score);
}
}
Err(e) => {
println!("{}", e);
}
}
match classifications {
Ok(classifications) => {
for classification in classifications {
println!("{},{}", classification.entity_group, classification.word);
}
}
Err(e) => {
println!("{}", e);
}
}
match answer {
Ok(answer) => {
println!("{}", answer.answer)
}
Err(e) => {
println!("{}", e);
}
}
}