use serde::{ Deserialize, Serialize };
#[ derive( Debug, Clone ) ]
pub enum ImageInput
{
Bytes( Vec< u8 > ),
Base64( String ),
Url( String ),
}
impl ImageInput
{
#[ inline ]
#[ must_use ]
pub fn from_bytes( bytes : Vec< u8 > ) -> Self
{
Self::Bytes( bytes )
}
#[ inline ]
#[ must_use ]
pub fn from_base64( data : impl Into< String > ) -> Self
{
Self::Base64( data.into() )
}
#[ inline ]
#[ must_use ]
pub fn from_url( url : impl Into< String > ) -> Self
{
Self::Url( url.into() )
}
#[ inline ]
#[ must_use ]
pub fn to_base64( &self ) -> String
{
match self
{
Self::Bytes( bytes ) => base64_encode( bytes ),
Self::Base64( data ) => data.clone(),
Self::Url( url ) => url.clone(), }
}
}
fn base64_encode( bytes : &[ u8 ] ) -> String
{
use base64::{ Engine, engine::general_purpose };
general_purpose::STANDARD.encode( bytes )
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct ClassificationResult
{
pub label : String,
pub score : f64,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct BoundingBox
{
pub xmin : f64,
pub ymin : f64,
pub xmax : f64,
pub ymax : f64,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct DetectionResult
{
pub label : String,
pub score : f64,
#[ serde( rename = "box" ) ]
pub box_coords : BoundingBox,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct CaptionResult
{
pub generated_text : String,
}