huggingface_inference_rs

Crates.iohuggingface_inference_rs
lib.rshuggingface_inference_rs
version0.5.0
sourcesrc
created_at2023-06-28 13:39:16.160904
updated_at2023-07-03 09:51:20.980212
descriptionthis package is a small wrapper for hugging face Inference API
homepage
repositoryhttps://github.com/Yvonne-Aizawa/hugging-face-inference-api-wrapper
max_upload_size
id902112
size48,325
(Yvonne-Aizawa)

documentation

README

Hugging face api wrapper

what is this?

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

example use

[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);
        }
    }
}

Commit count: 6

cargo fmt