-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.rs
More file actions
78 lines (66 loc) · 2.2 KB
/
Copy pathbasic.rs
File metadata and controls
78 lines (66 loc) · 2.2 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use realitydefender::{Client, Config, UploadOptions};
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get API key from environment variable
let api_key = env::var("REALITY_DEFENDER_API_KEY")
.expect("REALITY_DEFENDER_API_KEY environment variable must be set");
// Initialize the client
let client = Client::new(Config {
api_key,
..Default::default()
})?;
// Path to the file to analyze - make sure this file exists
let file_path = "files/test_image.jpg";
println!("Checking if file exists at path: {}", file_path);
if !std::path::Path::new(file_path).exists() {
println!("Warning: File does not exist at path: {}", file_path);
println!("Please provide a valid file path to an existing image or video file.");
return Ok(());
}
println!("Uploading file: {}", file_path);
// Upload the file
let upload_result = client
.upload(UploadOptions {
file_path: file_path.to_string(),
})
.await?;
println!(
"Upload successful! Request ID: {}",
upload_result.request_id
);
// Get the analysis result with waiting
println!("Waiting for analysis result...");
let result = client
.get_result(
&upload_result.request_id,
Some(realitydefender::GetResultOptions {
max_attempts: Some(30),
polling_interval: Some(2000),
}),
)
.await?;
// Print the result
println!("Analysis complete!");
println!("Status: {}", result.status);
if let Some(score) = result.score {
println!("Score: {:.4} ({:.1}%)", score, score * 100.0);
} else {
println!("No overall score available");
}
// Print model-specific results
if !result.models.is_empty() {
println!("\nModel-specific results:");
for model in result.models {
println!(
"- {}: Status: {}, Score: {}",
model.name,
model.status,
model
.score
.map_or("N/A".to_string(), |s| format!("{:.4}", s))
);
}
}
Ok(())
}