DamarJati commited on
Commit
7f6ca2e
·
verified ·
1 Parent(s): 8b91f4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -10,7 +10,16 @@ def load_model(selected_model):
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)]
 
 
 
 
 
 
 
 
 
14
 
15
  def process_image(image, prompt, neg_prompt, model):
16
  # Logika untuk memproses gambar menggunakan model
@@ -23,37 +32,43 @@ def controlnet_process(image, controlnet_type, model):
23
  with gr.Blocks() as app:
24
  # Dropdown untuk memilih model di luar tab
25
  with gr.Row():
26
- model_dropdown = gr.Dropdown(choices=models, label="Pilih Model")
27
 
28
  # Tab untuk Text-to-Image
29
  with gr.Tab("Text-to-Image"):
30
  with gr.Row():
31
  with gr.Column():
32
- prompt_input = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks")
33
- neg_prompt_input = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt")
 
 
 
 
 
 
 
 
 
34
  width_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Lebar", value=512)
35
  height_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Tinggi", value=512)
36
  scheduler_input = gr.Dropdown(choices=["Euler", "LMS", "DDIM"], label="Scheduler")
37
  num_steps_input = gr.Slider(minimum=1, maximum=100, step=1, label="Num Steps", value=20)
38
  num_images_input = gr.Slider(minimum=1, maximum=10, step=1, label="Num Images", value=1)
39
- generate_button = gr.Button("Generate")
40
-
41
- with gr.Column():
42
- output_gallery = gr.Gallery(label="Hasil Gambar")
43
 
44
  def update_images(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, model):
45
  # Update fungsi sesuai kebutuhan
46
- return generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, model)
 
47
 
48
- 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)
49
 
50
  # Tab untuk Image-to-Image
51
  with gr.Tab("Image-to-Image"):
52
  with gr.Row():
53
  with gr.Column():
54
  image_input = gr.Image(label="Unggah Gambar")
55
- prompt_input_i2i = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks")
56
- neg_prompt_input_i2i = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt")
57
  generate_button_i2i = gr.Button("Proses Gambar")
58
 
59
  with gr.Column():
 
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)], {
14
+ "prompt": prompt,
15
+ "neg_prompt": neg_prompt,
16
+ "width": width,
17
+ "height": height,
18
+ "scheduler": scheduler,
19
+ "num_steps": num_steps,
20
+ "num_images": num_images,
21
+ "model": model
22
+ }
23
 
24
  def process_image(image, prompt, neg_prompt, model):
25
  # Logika untuk memproses gambar menggunakan model
 
32
  with gr.Blocks() as app:
33
  # Dropdown untuk memilih model di luar tab
34
  with gr.Row():
35
+ model_dropdown = gr.Dropdown(choices=models, label="Pilih Model", elem_id="model-dropdown").style(width=200)
36
 
37
  # Tab untuk Text-to-Image
38
  with gr.Tab("Text-to-Image"):
39
  with gr.Row():
40
  with gr.Column():
41
+ prompt_input = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks", lines=2)
42
+ neg_prompt_input = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt", lines=2)
43
+ generate_button = gr.Button("Generate")
44
+
45
+ with gr.Column():
46
+ # Output gallery and text
47
+ output_gallery = gr.Gallery(label="Hasil Gambar", elem_id="output-gallery")
48
+ output_text = gr.Textbox(label="Output JSON", elem_id="output-text", lines=10)
49
+
50
+ with gr.Row():
51
+ with gr.Column():
52
  width_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Lebar", value=512)
53
  height_input = gr.Slider(minimum=64, maximum=2048, step=64, label="Tinggi", value=512)
54
  scheduler_input = gr.Dropdown(choices=["Euler", "LMS", "DDIM"], label="Scheduler")
55
  num_steps_input = gr.Slider(minimum=1, maximum=100, step=1, label="Num Steps", value=20)
56
  num_images_input = gr.Slider(minimum=1, maximum=10, step=1, label="Num Images", value=1)
 
 
 
 
57
 
58
  def update_images(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, model):
59
  # Update fungsi sesuai kebutuhan
60
+ images, json_output = generate_image(prompt, neg_prompt, width, height, scheduler, num_steps, num_images, model)
61
+ return images, json_output
62
 
63
+ 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])
64
 
65
  # Tab untuk Image-to-Image
66
  with gr.Tab("Image-to-Image"):
67
  with gr.Row():
68
  with gr.Column():
69
  image_input = gr.Image(label="Unggah Gambar")
70
+ prompt_input_i2i = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks", lines=2)
71
+ neg_prompt_input_i2i = gr.Textbox(label="Neg Prompt", placeholder="Masukkan negasi prompt", lines=2)
72
  generate_button_i2i = gr.Button("Proses Gambar")
73
 
74
  with gr.Column():