|
from diffusers import StableDiffusionXLPipeline |
|
import torch |
|
from gradio import Interface, Image, Dropdown, Slider |
|
import gradio as gr |
|
import spaces |
|
|
|
model_id = "RunDiffusion/Juggernaut-X-v10" |
|
pipe = StableDiffusionXLPipeline.from_pretrained(model_id, torch_dtype=torch.float16) |
|
pipe = pipe.to("cuda") |
|
|
|
@spaces.GPU() |
|
def text_to_image(prompt, negative_prompt, steps, guidance_scale, progress=gr.Progress(track_tqdm=True)): |
|
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, guidance_scale=guidance_scale).images[0] |
|
return image |
|
|
|
|
|
gradio_interface = Interface( |
|
fn=text_to_image, |
|
inputs=[ |
|
gr.Textbox(label="Prompt", lines=2, placeholder="Enter your prompt here..."), |
|
gr.Textbox(label="Negative Prompt", lines=2, placeholder="What to exclude from the image..."), |
|
gr.Slider(minimum=1, maximum=65, value=50, label="Steps", step=1), |
|
gr.Slider(minimum=1, maximum=20, value=7.5, label="Guidance Scale", step=0.1) |
|
], |
|
outputs=Image(type="pil", show_download_button=True), |
|
examples=[ |
|
["magical kitten, 4k, high quality, (masterpiece)"], |
|
], |
|
cache_examples=False, |
|
theme=gr.themes.Soft() |
|
) |
|
gradio_interface.launch() |