Function process_json_to_caption

Source
pub async fn process_json_to_caption(input_path: &Path) -> Result<()>
Expand description

Converts a JSON file containing tag probabilities into a caption file.

This function reads a JSON file containing tag-probability pairs, filters tags based on a probability threshold (0.2), and writes the selected tags to a new .txt file. Tags are sorted by probability in descending order.

§Arguments

  • input_path - Path to the input JSON file

§Returns

  • io::Result<()> - Success or failure of the operation

§Errors

Returns an error if:

  • The input file cannot be read
  • The content cannot be parsed as JSON
  • The output file cannot be written

§Format

Input JSON should be in the format:

{
    "tag1": 0.9,
    "tag2": 0.5,
    "tag3": 0.1
}