File size: 5,440 Bytes
ce640b1
 
 
 
a15d400
ce640b1
 
58e7d79
ce640b1
 
 
eaf1b5a
ce640b1
580d690
ce640b1
58e7d79
 
 
 
 
ce640b1
58e7d79
ce640b1
 
580d690
58e7d79
a15d400
 
 
580d690
58e7d79
ce640b1
eaf1b5a
eeebdaa
c8a7013
eeebdaa
 
39c7af4
 
c8a7013
eaf1b5a
5276966
580d690
eaf1b5a
 
 
 
 
 
 
580d690
5276966
580d690
7b2b8c3
580d690
 
 
eaf1b5a
ce640b1
eaf1b5a
ce640b1
f9ebabd
ce640b1
58e7d79
ce640b1
 
58e7d79
 
7f6ca2e
 
58e7d79
 
 
 
ce640b1
58e7d79
ce640b1
58e7d79
ce640b1
f9ebabd
ce640b1
58e7d79
ce640b1
 
58e7d79
 
 
 
 
 
 
ce640b1
58e7d79
ce640b1
58e7d79
ce640b1
f9ebabd
ce640b1
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import gradio as gr

# Daftar model dan ControlNet
models = ["Model A", "Model B", "Model C"]
vae = ["VAE A", "VAE B", "VAE C"]
controlnet_types = ["Canny", "Depth", "Normal", "Pose"]

# Fungsi placeholder
def load_model(selected_model):
    return f"Model {selected_model} telah dimuat."

def generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, cfg_scale, seed, model):
    # Logika untuk menghasilkan gambar dari teks menggunakan model
    return [f"Gambar {i+1} untuk prompt '{prompt}' dengan model '{model}'" for i in range(num_images)], {"prompt": prompt, "neg_prompt": neg_prompt}

def process_image(image, prompt, neg_prompt, model):
    # Logika untuk memproses gambar menggunakan model
    return f"Proses gambar dengan prompt '{prompt}' dan model '{model}'"

def controlnet_process(image, controlnet_type, model):
    # Logika untuk memproses gambar menggunakan ControlNet
    return f"Proses gambar dengan ControlNet '{controlnet_type}' dan model '{model}'"

with gr.Blocks() as app:
    # Dropdown untuk memilih model di luar tab dengan lebar kecil
    with gr.Row():
        model_dropdown = gr.Dropdown(choices=models, label="Model", elem_id="model-dropdown", value="Model B", scale=0.3)
        vae_dropdown = gr.Dropdown(choices=vae, label="VAE", elem_id="vae-dropdown", value="VAE C", scale=0.3)

    
    # Tab untuk Text-to-Image
    with gr.Tab("Text-to-Image"):
        # Prompt dan Neg Prompt
        with gr.Row():
            with gr.Column(scale=1):  # Scale 1 ensures full width
                prompt_input = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks", lines=2, elem_id="prompt-input")
                neg_prompt_input = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt", lines=2, elem_id="neg-prompt-input")
           
            generate_button = gr.Button("Generate", elem_id="generate-button", scale=0.13)
        
        with gr.Row():
            with gr.Column():
                # Konfigurasi
                scheduler_input = gr.Dropdown(choices=["Euler", "LMS", "DDIM"], label="Sampling method")
                num_steps_input = gr.Slider(minimum=1, maximum=100, step=1, label="Sampling steps", value=20)
                width_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Width", value=512)
                height_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Height", value=512)
                cfg_scale_input = gr.Slider(minimum=1, maximum=20, step=1, label="CFG Scale", value=7)
                seed_input = gr.Number(label="Seed", value=-1)
                num_images_input = gr.Slider(minimum=1, maximum=10, step=1, label="Batch size", value=1)
            
            with gr.Column():
                # Gallery untuk output gambar
                output_gallery = gr.Gallery(label="Hasil Gambar")
                # Output teks JSON di bawah gallery
                output_text = gr.Textbox(label="Output JSON", placeholder="Hasil dalam format JSON", lines=2)

        def update_images(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, cfg_scale, seed, model):
            # Update fungsi sesuai kebutuhan
            return generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, cfg_scale, seed, model)
        
        generate_button.click(fn=update_images, inputs=[prompt_input, neg_prompt_input, width_input, height_input, scheduler_input, num_steps_input, num_images_input, cfg_scale_input, seed_input, model_dropdown, vae_dropdown], outputs=[output_gallery, output_text])

    # Tab untuk Image-to-Image
    with gr.Tab("Image-to-Image"):
        with gr.Row():
            with gr.Column():
                image_input = gr.Image(label="Unggah Gambar")
                prompt_input_i2i = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks", lines=2)
                neg_prompt_input_i2i = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt", lines=2)
                generate_button_i2i = gr.Button("Proses Gambar")
            
            with gr.Column():
                output_image_i2i = gr.Image(label="Hasil Gambar")
        
        def process_image_func(image, prompt, neg_prompt, model):
            # Update fungsi sesuai kebutuhan
            return process_image(image, prompt, neg_prompt, model)
        
        generate_button_i2i.click(fn=process_image_func, inputs=[image_input, prompt_input_i2i, neg_prompt_input_i2i, model_dropdown, vae_dropdown], outputs=output_image_i2i)

    # Tab untuk ControlNet
    with gr.Tab("ControlNet"):
        with gr.Row():
            with gr.Column():
                controlnet_dropdown = gr.Dropdown(choices=controlnet_types, label="Pilih Tipe ControlNet")
                controlnet_image_input = gr.Image(label="Unggah Gambar untuk ControlNet")
                controlnet_button = gr.Button("Proses dengan ControlNet")
            
            with gr.Column():
                controlnet_output_image = gr.Image(label="Hasil ControlNet")
        
        def controlnet_process_func(image, controlnet_type, model):
            # Update fungsi sesuai kebutuhan
            return controlnet_process(image, controlnet_type, model)
        
        controlnet_button.click(fn=controlnet_process_func, inputs=[controlnet_image_input, controlnet_dropdown, model_dropdown, vae_dropdown], outputs=controlnet_output_image)

# Jalankan antarmuka
app.launch()