DamarJati commited on
Commit
eaf1b5a
·
verified ·
1 Parent(s): 3c7b24e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -8,7 +8,7 @@ controlnet_types = ["Canny", "Depth", "Normal", "Pose"]
8
  def load_model(selected_model):
9
  return f"Model {selected_model} telah dimuat."
10
 
11
- def generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, model):
12
  # Logika untuk menghasilkan gambar dari teks menggunakan model
13
  return [f"Gambar {i+1} untuk prompt '{prompt}' dengan model '{model}'" for i in range(num_images)], {"prompt": prompt, "neg_prompt": neg_prompt}
14
 
@@ -27,36 +27,36 @@ with gr.Blocks() as app:
27
 
28
  # Tab untuk Text-to-Image
29
  with gr.Tab("Text-to-Image"):
 
30
  with gr.Row():
31
- with gr.Column(scale=80):
32
- # Prompt dan Neg Prompt
33
- prompt_input = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks", lines=2, elem_id="prompt-input")
34
- neg_prompt_input = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt", lines=2, elem_id="neg-prompt-input")
35
-
36
- with gr.Column(scale=20):
37
- # Tombol Generate
38
- generate_button = gr.Button("Generate", elem_id="generate-button")
39
-
40
  with gr.Row():
41
- with gr.Column():
 
 
 
42
  # Konfigurasi
43
- width_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Lebar", value=512)
44
- height_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Tinggi", value=512)
45
- scheduler_input = gr.Dropdown(choices=["Euler", "LMS", "DDIM"], label="Scheduler")
46
- num_steps_input = gr.Slider(minimum=1, maximum=100, step=1, label="Num Steps", value=20)
47
- num_images_input = gr.Slider(minimum=1, maximum=10, step=1, label="Num Images", value=1)
 
 
48
 
49
- with gr.Column():
50
  # Gallery untuk output gambar
51
  output_gallery = gr.Gallery(label="Hasil Gambar")
52
  # Output teks JSON di bawah gallery
53
  output_text = gr.Textbox(label="Output JSON", placeholder="Hasil dalam format JSON", lines=2)
54
 
55
- def update_images(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, model):
56
  # Update fungsi sesuai kebutuhan
57
- return generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, model)
58
 
59
- generate_button.click(fn=update_images, inputs=[prompt_input, neg_prompt_input, width_input, height_input, scheduler_input, num_steps_input, num_images_input, model_dropdown], outputs=[output_gallery, output_text])
60
 
61
  # Tab untuk Image-to-Image
62
  with gr.Tab("Image-to-Image"):
 
8
  def load_model(selected_model):
9
  return f"Model {selected_model} telah dimuat."
10
 
11
+ def generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, cfg_scale, seed, model):
12
  # Logika untuk menghasilkan gambar dari teks menggunakan model
13
  return [f"Gambar {i+1} untuk prompt '{prompt}' dengan model '{model}'" for i in range(num_images)], {"prompt": prompt, "neg_prompt": neg_prompt}
14
 
 
27
 
28
  # Tab untuk Text-to-Image
29
  with gr.Tab("Text-to-Image"):
30
+ # Prompt dan Neg Prompt
31
  with gr.Row():
32
+ prompt_input = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks", lines=2, elem_id="prompt-input")
33
+ generate_button = gr.Button("Generate", elem_id="generate-button")
34
+
 
 
 
 
 
 
35
  with gr.Row():
36
+ neg_prompt_input = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt", lines=2, elem_id="neg-prompt-input")
37
+
38
+ with gr.Row():
39
+ with gr.Column(scale=2):
40
  # Konfigurasi
41
+ scheduler_input = gr.Dropdown(choices=["Euler", "LMS", "DDIM"], label="Sampling method")
42
+ num_steps_input = gr.Slider(minimum=1, maximum=100, step=1, label="Sampling steps", value=20)
43
+ width_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Width", value=512)
44
+ height_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Height", value=512)
45
+ cfg_scale_input = gr.Slider(minimum=1, maximum=20, step=1, label="CFG Scale", value=7)
46
+ seed_input = gr.Number(label="Seed", value=-1)
47
+ num_images_input = gr.Slider(minimum=1, maximum=10, step=1, label="Batch size", value=1)
48
 
49
+ with gr.Column(scale=1):
50
  # Gallery untuk output gambar
51
  output_gallery = gr.Gallery(label="Hasil Gambar")
52
  # Output teks JSON di bawah gallery
53
  output_text = gr.Textbox(label="Output JSON", placeholder="Hasil dalam format JSON", lines=2)
54
 
55
+ def update_images(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, cfg_scale, seed, model):
56
  # Update fungsi sesuai kebutuhan
57
+ return generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, cfg_scale, seed, model)
58
 
59
+ 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], outputs=[output_gallery, output_text])
60
 
61
  # Tab untuk Image-to-Image
62
  with gr.Tab("Image-to-Image"):