File size: 1,209 Bytes
7091ee2
 
 
0bbc490
f33aefe
045d91e
e6c644a
 
f33aefe
e6c644a
 
f33aefe
7091ee2
 
 
 
f33aefe
7091ee2
 
 
507ba49
0bbc490
7091ee2
0bbc490
7091ee2
 
5119f6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from diffusers import DiffusionPipeline

def generate_image(modelsyu, prompt, negative_prompt):
    pipeline = DiffusionPipeline.from_pretrained(modelsyu)
    pipeline.to("cpu")
    # Attempt to generate an image with the negative prompt if supported
    try:
        image = pipeline(prompt, negative_prompt=negative_prompt).images[0]
    except TypeError:
        # Fallback if negative_prompt is not supported
        image = pipeline(prompt).images[0]
    return image

# Define the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Text to Image Generation Custom Models Demo")
    prompt = gr.Textbox(label="Prompt", placeholder="Enter your text prompt here")
    negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter your negative prompt here")
    submit_button = gr.Button("Generate Image")
    with gr.Accordion('Load your custom models first'):
        basem = gr.Textbox(label="Your Lora model", value="John6666/pony-diffusion-v6-xl-sdxl-spo")  
    output_image = gr.Image(label="Generated Image")
    submit_button.click(generate_image, inputs=[basem, prompt, negative_prompt], outputs=output_image)

# Launch the demo
demo.launch(queue=False)