import gradio as gr import torch # from diffusers import DiffusionPipeline from diffusers import StableDiffusionPipeline def generate(prompt, negative_prompts, samples, steps,scale, seed): pipeline = StableDiffusionPipeline.from_pretrained("jayparmr/icbinp", use_auth_token="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", torch_dtype=torch.float16) pipeline.to("cuda") # return pipeline(prompt).images[0] generator = torch.Generator(device="cuda").manual_seed(int(seed)) images_list = pipeline( [prompt] * samples, negative_prompt= [negative_prompts] * samples, num_inference_steps=steps, guidance_scale=scale, generator=generator, ) images = [] print(images_list) for i, image in enumerate(images_list["images"]): images.append(image) return images block = gr.Blocks() with block: with gr.Group(): with gr.Box(): with gr.Row().style(mobile_collapse=False, equal_height=True): text = gr.Textbox( label="Enter your prompt", show_label=False, max_lines=1, placeholder="Enter your prompt", ).style( border=(True, False, True, True), rounded=(True, False, False, True), container=False, ) negative_text = gr.Textbox( label="Enter your negative prompt", show_label=False, max_lines=1, placeholder="Enter your negative prompt", ).style( border=(True, False, True, True), rounded=(True, False, False, True), container=False, ) btn = gr.Button("Generate image").style( margin=False, rounded=(False, True, True, False), ) # with gr.Row().style(mobile_collapse=False, equal_height=True): # btn = gr.Button("Generate image").style( # margin=False, # rounded=(False, True, True, False), # ) gallery = gr.Gallery( label="Generated images", show_label=False, elem_id="gallery" ).style(grid=[2], height="auto") # advanced_button = gr.Button("Advanced options", elem_id="advanced-btn") with gr.Row(elem_id="advanced-options"): samples = gr.Slider(label="Images", minimum=1, maximum=4, value=1, step=1) steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=25, step=1) scale = gr.Slider( label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1 ) seed = gr.Slider( label="Seed", minimum=0, maximum=2147483647, step=1, randomize=True, ) text.submit(generate, inputs=[text,negative_text, samples, steps, scale, seed], outputs=gallery) btn.click(generate, inputs=[text,negative_text, samples, steps, scale, seed], outputs=gallery) # advanced_button.click( # None, # [], # text, # ) block.launch() # iface = gr.Interface(fn=generate, inputs="text", outputs="image") # iface.launch()