Skip to content

Commit

Permalink
Text2img handle size params
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Sep 17, 2024
1 parent dedf2bc commit ea9cd79
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions runtimes/dummy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,28 @@ async fn healthcheck(_req: HttpRequest) -> impl Responder {
HttpResponse::Ok()
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Text2ImageBody {
pub width: Option<u32>,
pub height: Option<u32>,
}

#[post("/sdapi/v1/txt2img")]
async fn text2img(_req: HttpRequest) -> impl Responder {
async fn text2img(params: web::Json<Text2ImageBody>) -> impl Responder {
log::info!("Endpoint: sdapi/v1/txt2img");

let mut bytes: Vec<u8> = Vec::new();
match fractal(800, 800).write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png) {

let params = params.into_inner();
let width = params.width.unwrap_or(800);
let height = params.height.unwrap_or(800);

match fractal(width, height).write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png) {
Ok(_) => HttpResponse::Ok().json(json!({ "images": [BASE64_STANDARD.encode(bytes)] })),
Err(e) => {
log::error!("Error generating image: {e}");
return HttpResponse::InternalServerError()
.body(format!("Error generating image: {e}"));
HttpResponse::InternalServerError().body(format!("Error generating image: {e}"))
}
}
}
Expand Down

0 comments on commit ea9cd79

Please sign in to comment.