Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 32 |
-
|
| 33 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
# Konfigurasi
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
| 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"):
|