import os import gradio as gr from huggingface_hub import InferenceClient client = InferenceClient() from gradio_imageslider import ImageSlider def refine_image(image, model ,prompt, negative_prompt, num_inference_steps, guidance_scale, seed, strength): refined_image = client.image_to_image( image, prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, seed=seed, model=model, strength=strength ) return [image, refined_image] with gr.Blocks() as demo: with gr.Row(): with gr.Column(): refiner_image = gr.Image(type="filepath") with gr.Accordion("Advanced Options", open=False): refiner_prompt = gr.Textbox(lines=3, label="Prompt") refiner_negative_prompt = gr.Textbox(lines=3, label="Negative Prompt") refiner_strength = gr.Slider( label="Strength", minimum=0, maximum=300, step=0.01, value=1 ) refiner_num_inference_steps = gr.Slider( label="Inference steps", minimum=3, maximum=300, step=1, value=25 ) refiner_guidance_scale = gr.Slider( label="Guidance scale", minimum=0.0, maximum=50.0, step=0.1, value=12 ) refiner_seed = gr.Slider( label="Seed", info="-1 denotes a random seed", minimum=-1, maximum=423538377342, step=1, value=-1 ) refiner_model = gr.Textbox(label="Model", value="stabilityai/stable-diffusion-xl-refiner-1.0") refiner_btn = gr.Button("Refine") with gr.Column(): refiner_output = ImageSlider(label="Before / After") refiner_btn.click( refine_image, inputs=[refiner_image, refiner_model, refiner_prompt, refiner_negative_prompt, refiner_num_inference_steps, refiner_guidance_scale, refiner_seed, refiner_strength], outputs=refiner_output ) demo.launch(show_error=True)