File size: 2,360 Bytes
46b8097
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a37e1e
46b8097
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a37e1e
46b8097
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import gradio as gr
from stablepy import Model_Diffusers


# Define the function to generate images
def generate_image(prompt, num_steps, guidance_scale, sampler, img_width, img_height, upscaler_model_path, upscaler_increases_size, hires_steps, base_model_id):

    model = Model_Diffusers(
        base_model_id=base_model_id,
        task_name='txt2img',
    )

    image, info_image = model(
        prompt=prompt,
        num_steps=num_steps,
        guidance_scale=guidance_scale,
        sampler=sampler,
        img_width=img_width,
        img_height=img_height,
        upscaler_model_path=upscaler_model_path,
        upscaler_increases_size=upscaler_increases_size,
        hires_steps=hires_steps,
    )
    return image[0]

# Create the Gradio Blocks UI
with gr.Blocks(gr.themes.Ocean(), title="StablePY") as demo:
    gr.Markdown("# StablePY")

    moelpah = gr.Textbox(label="model", placeholder="user/repo")
    
    with gr.Row():
        prompt = gr.Textbox(label="Prompt", value="highly detailed portrait of an underwater city, with towering spires and domes rising up from the ocean floor")
    
    with gr.Row():
        num_steps = gr.Slider(label="Number of Steps", minimum=1, maximum=100, value=30)
        guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=20.0, value=7.5)
        sampler = gr.Dropdown(label="Sampler", choices=["DPM++ 2M", "DDIM", "Euler A"], value="DPM++ 2M")
    
    with gr.Row():
        img_width = gr.Number(label="Image Width", value=1024)
        img_height = gr.Number(label="Image Height", value=1024)
    
    with gr.Row():
        upscaler_model_path = gr.Textbox(label="Upscaler Model Path", value="./upscaler/RealESRGAN_x4plus_anime_6B.pth", visible=False)
        upscaler_increases_size = gr.Number(label="Upscaler Increase Size", value=1.5)
        hires_steps = gr.Number(label="Hires Steps", value=25)

    with gr.Row():
        generate_button = gr.Button("Generate")
    
    with gr.Row():
        output_image = gr.Image(label="Generated Image")

    # Link the button to the generation function
    generate_button.click(
        generate_image,
        inputs=[moelpah, prompt, num_steps, guidance_scale, sampler, img_width, img_height, upscaler_model_path, upscaler_increases_size, hires_steps],
        outputs=[output_image]
    )

# Launch the app
demo.launch()