import os import gradio as gr from gradio_client import Client, handle_file from gradio_imageslider import ImageSlider stable_diffusion_xl_refiner_10 = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-refiner-1.0" refiner_client = None def refine_image(image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed): global refiner_client if refiner_client is None: refiner_client = Client(stable_diffusion_xl_refiner_10) job = refiner_client.submit( inputs=image, parameters={ "prompt":prompt, "negative_prompt": negative_prompt, "num_inference_steps": num_inference_steps, "guidance_scale": guidance_scale, "seed": seed, } ) return job.result() with gr.Blocks() as demo: image = gr.Image() prompt = gr.Textbox(lines=3, label="Prompt") negative_prompt = gr.Textbox(lines=3, label="Negative Prompt") num_inference_steps = gr.Number(default=25, label="Number of Inference Steps") guidance_scale = gr.Slider(minimum=3, maximum=30, default=12, label="Guidance Scale") seed = gr.Number(default=-1, label="Seed") refine_btn = gr.Button(text="Refine") output = gr.Image() refine_btn.click(refine_image, inputs=[image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed], outpus=output) demo.launch()