-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipelines.rs
54 lines (38 loc) · 1.79 KB
/
pipelines.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::error::Error;
use txtai::segmentation::Segmentation;
use txtai::summary::Summary;
use txtai::textractor::Textractor;
use txtai::transcription::Transcription;
use txtai::translation::Translation;
use txtai::workflow::Workflow;
/// Example pipeline and workflow functionality.
///
/// Uses files from txtai unit tests: https://github.com/neuml/txtai/releases/download/v2.0.0/tests.tar.gz
pub async fn pipelines() -> Result<(), Box<dyn Error>> {
let service = "http://localhost:8000";
let segment = Segmentation::with_url(service);
let sentences = "This is a test. And another test.";
println!("---- Segmented Text ----");
println!("{:?}", segment.segment(sentences).await?);
let textractor = Textractor::with_url(service);
let text = textractor.textract("/tmp/txtai/article.pdf").await?;
println!("\n---- Extracted Text ----");
println!("{:?}", text);
let summary = Summary::with_url(service);
let summarytext = summary.summary(text.as_string().unwrap(), None, None).await?;
println!("\n---- Summary Text ----");
println!("{:?}", summarytext);
let translate = Translation::with_url(service);
let translation = translate.translate(&summarytext, Some("es"), None).await?;
println!("\n---- Summary Text in Spanish ----");
println!("{:?}", translation);
let workflow = Workflow::with_url(service);
let output = workflow.workflow("sumspanish", &vec!["file:///tmp/txtai/article.pdf"]).await?;
println!("\n---- Workflow [Extract Text->Summarize->Translate] ----");
println!("{:?}", output);
let transcribe = Transcription::with_url(service);
let transcription = transcribe.transcribe("/tmp/txtai/Make_huge_profits.wav").await?;
println!("\n---- Transcribed Text ----");
println!("{:?}", transcription);
Ok(())
}