Spaces:
Runtime error
Runtime error
File size: 15,224 Bytes
c0b6d7e 79fab79 c0b6d7e 315ad96 2a651a9 c0b6d7e 28eae20 c0b6d7e 24d034a 647fe33 c0b6d7e 12a12a5 c0b6d7e 12a12a5 c0b6d7e 6b0140b 6c2f5e7 6b0140b c0b6d7e bc2fb74 c0b6d7e 7f3bc9f 5a2bd61 ea77b9e 24d034a ea77b9e bc2fb74 c0b6d7e 3fce290 fcb87f2 387b1a1 bc2fb74 c0b6d7e 82b8988 fcb87f2 bc2fb74 82b8988 fcb87f2 bc2fb74 82b8988 fcb87f2 bc2fb74 82b8988 fcb87f2 bc2fb74 82b8988 fcb87f2 9cb7448 fcb87f2 9cb7448 fcb87f2 bc2fb74 c0b6d7e fcb87f2 c0b6d7e fcb87f2 c0b6d7e bc078cd 12a12a5 fcb87f2 bc2fb74 f43236d c0b6d7e a529f7a ebab327 a529f7a c0b6d7e a529f7a 1ef4f73 a529f7a 1ef4f73 c0b6d7e db62bcb c0b6d7e 86e8dab bdf57fd 86e8dab c0b6d7e bdf57fd 3bfd4f8 bdf57fd 789cc44 bdf57fd 789cc44 c0b6d7e bdf57fd c0b6d7e 168d548 64f5bc1 c0b6d7e 64f5bc1 c0b6d7e 168d548 c0b6d7e 23e4822 6d7f6f4 3bfd4f8 6d7f6f4 23e4822 f01c980 23e4822 c88c787 23e4822 c0b6d7e |
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
import gradio as gr
from gradio_imageslider import ImageSlider
import os
import modules.wdtagger
# Daftar model dan ControlNet
models = ["Model A", "Model B", "Model C"]
vae = ["VAE A", "VAE B", "VAE C"]
controlnet_types = [
"Canny", # Edge detection using Canny algorithm
"Depth", # Depth estimation from images
"Normal", # Normal map generation
"Pose", # Pose estimation
"Segmentation", # Semantic segmentation
"Scribble", # Sketch or scribble input
"OpenPose", # OpenPose-based pose estimation
"MLSD", # Line segment detection
"HED", # Holistically-Nested Edge Detection
"Color", # Colorization input
"Binary", # Binary mask input
"Scribble+Edge", # Combination of scribble and edge detection
"OpenPose+Depth" # Combination of OpenPose and depth estimation
]
schedulers = [
"EulerDiscreteScheduler",
"EulerAncestralDiscreteScheduler",
"LMSDiscreteScheduler", # Linear Multistep Methods
"DDIMScheduler", # Denoising Diffusion Implicit Models
"PNDMScheduler", # Pseudo Numerical Methods for Diffusion Models
"HeunDiscreteScheduler", # Heun's method
"DPMSolverMultistepScheduler", # Diffusion Probabilistic Model Solver
"DDPMScheduler", # Denoising Diffusion Probabilistic Models
"DPMSolverSinglestepScheduler", # Single-step version of DPM-Solver
"DPMSolver++MultistepScheduler", # Enhanced version of DPM-Solver
"IPNDMScheduler", # Improved Pseudo Numerical Methods for Diffusion Models
]
# Fungsi placeholder
def load_model_func(checkpoint, vae):
return f"Model {checkpoint} telah dimuat."
def generative_t2i(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 generative_i2i(image, prompt, neg_prompt, model):
# Logika untuk memproses gambar menggunakan model
return f"Proses gambar dengan prompt '{prompt}' dan model '{model}'"
def intpaint_func (image, controlnet_type, model):
# Update fungsi sesuai kebutuhan
return controlnet_process(image, controlnet_type, model)
def gradio_process_image (image, controlnet_type, model):
# Update fungsi sesuai kebutuhan
return controlnet_process(image, controlnet_type, model)
with gr.Blocks(css="style.css") as app:
# Dropdown untuk memilih model di luar tab dengan lebar kecil
with gr.Column():
with gr.Row():
checkpoint = gr.Dropdown(choices=models, label="Model", value=models[0])
vae = gr.Dropdown(choices=vae, label="VAE", value=vae[0])
load_model = gr.Button("Load", elem_id="load_model")
load_model.click(
fn=load_model_func,
inputs=[checkpoint, vae],
outputs=[])
# Tab untuk Text-to-Image
with gr.Tab("Text-to-Image"):
with gr.Row():
with gr.Column(scale=1):
prompt_t2i = gr.Textbox(label="Prompt", placeholder="Enter Prompt", lines=2, elem_id="prompt-input")
neg_prompt_t2i = gr.Textbox(label="Negative prompt", placeholder="Enter Negative Prompt (optional)", lines=2, elem_id="neg-prompt-input")
generate_t2i = gr.Button("Generate", elem_id="generate_t2i", scale=0.13)
with gr.Row():
with gr.Column():
with gr.Row():
scheduler_t2i = gr.Dropdown(choices=schedulers, label="Sampling method", value=schedulers[0])
seed_t2i = gr.Number(label="Seed", value=-1)
with gr.Row():
width_t2i = gr.Slider(minimum=128, maximum=2048, step=128, label="Width", value=1024)
batch_size_t2i = gr.Slider(minimum=1, maximum=24, step=1, label="Batch size", value=1)
with gr.Row():
height_t2i = gr.Slider(minimum=128, maximum=2048, step=128, label="Height", value=1024)
batch_count_t2i = gr.Slider(minimum=1, maximum=24, step=1, label="Batch Count", value=1)
with gr.Row():
num_steps_t2i = gr.Slider(minimum=1, maximum=100, step=1, label="Sampling steps", value=20)
cfg_scale_t2i = gr.Slider(minimum=1, maximum=20, step=1, label="CFG Scale", value=7)
with gr.Accordion("Hires. fix", open=False):
use_hires_t2i = gr.Checkbox(label="Use Hires?", value=False, scale=0)
with gr.Row():
upscaler_t2i = gr.Dropdown(choices=schedulers, label="Upscaler", value=schedulers[0])
upscale_by_t2i = gr.Slider(minimum=1, maximum=8, step=1, label="Upscale by", value=2)
with gr.Row():
hires_steps_t2i = gr.Slider(minimum=1, maximum=50, step=1, label="Hires Steps", value=20)
denois_strength_t2i = gr.Slider(minimum=0, maximum=1, step=0.02, label="Denoising Strength", value=2)
with gr.Column():
# Gallery untuk output gambar
output_gallery_t2i = gr.Gallery(label="Image Results")
# Output teks JSON di bawah gallery
output_text_t2i = gr.Textbox(label="Metadata", placeholder="Results are in Json format", lines=2)
generate_t2i.click(
fn=generative_t2i,
inputs=[prompt_t2i, neg_prompt_t2i, width_t2i, height_t2i, scheduler_t2i, num_steps_t2i, batch_size_t2i, batch_count_t2i, cfg_scale_t2i, seed_t2i, use_hires_t2i, upscaler_t2i, upscale_by_t2i, hires_steps_t2i, denois_strength_t2i],
outputs=[output_gallery_t2i, output_text_t2i]
)
# Tab untuk Image-to-Image
with gr.Tab("Image-to-Image"):
with gr.Row():
with gr.Column(scale=1):
prompt_input_i2i = gr.Textbox(label="Prompt", placeholder="Masukkan prompt teks", lines=2, elem_id="prompt-input")
neg_prompt_input_i2i = 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():
image_input = gr.Image(label="Unggah Gambar")
generate_button_i2i = gr.Button("Generate")
with gr.Row():
scheduler_input = gr.Dropdown(choices=schedulers, label="Sampling method", value=schedulers[0])
seed_input = gr.Number(label="Seed", value=-1)
with gr.Row():
steps = gr.Slider(minimum=1, maximum=100, step=1, label="Steps", value=20)
cfg_scale = gr.Slider(minimum=1, maximum=24, step=1, label="CFG Scale", value=7)
with gr.Row():
strength = gr.Slider(minimum=0, maximum=1, step=0.1, label="Strength", value=0.6)
with gr.Column():
output_image_i2i = gr.Image(label="Hasil Gambar")
generate_button_i2i.click(fn=generative_i2i, inputs=[image_input, scheduler_input, seed_input, steps, cfg_scale, strength], outputs=output_image_i2i)
# Tab untuk Intpainting
with gr.Tab ("Inpainting"):
with gr.Row():
with gr.Column(scale=1):
prompt_inpainting = gr.Textbox(label="Prompt", placeholder="Enter Prompt", lines=2, elem_id="prompt-input")
neg_prompt_inpainting = gr.Textbox(label="Negative prompt", placeholder="Enter Negative Prompt (optional)", lines=2, elem_id="neg-prompt-input")
generate_t2i = gr.Button("Generate", elem_id="generate_t2i", scale=0.13)
with gr.Row():
with gr.Column():
image = gr.ImageMask(sources=["upload"], layers=False, transforms=[], format="png", label="base image", show_label=True)
btn = gr.Button("Inpaint!", elem_id="run_button")
with gr.Row():
scheduler = gr.Dropdown(label="Schedulers", choices=schedulers, value=schedulers[0])
with gr.Row():
strength = gr.Slider(value=0.99, minimum=0.01, maximum=1.0, step=0.01, label="strength")
with gr.Row():
steps = gr.Slider(value=20, minimum=10, maximum=30, step=1, label="steps")
guidance_scale = gr.Slider(value=7.5, minimum=1.0, maximum=20.0, step=0.1, label="guidance_scale")
with gr.Column():
image_out = gr.Image(label="Output", elem_id="output-img")
btn.click(fn=intpaint_func, inputs=[image, prompt_inpainting, neg_prompt_inpainting, guidance_scale, steps, strength, scheduler], outputs=[image_out])
# Tab untuk Describe
with gr.Tab("Describe"):
with gr.Row():
with gr.Column():
# Components
image = gr.Image(type="pil", image_mode="RGBA", label="Input")
submit_button = gr.Button(value="Submit", variant="primary", size="lg")
model_repo = gr.Dropdown(modules.wdtagger.dropdown_list, value=modules.wdtagger.dropdown_list[0], label="Model")
general_thresh = gr.Slider(0, 1, step=modules.wdtagger.args.score_slider_step, value=modules.wdtagger.args.score_general_threshold, label="General Tags Threshold", scale=3)
general_mcut_enabled = gr.Checkbox(value=False, label="Use MCut threshold", scale=1)
character_thresh = gr.Slider(0, 1, step=modules.wdtagger.args.score_slider_step, value=modules.wdtagger.args.score_character_threshold, label="Character Tags Threshold", scale=3)
character_mcut_enabled = gr.Checkbox(value=False, label="Use MCut threshold", scale=1)
clear_button = gr.ClearButton(components=[image, model_repo, general_thresh, general_mcut_enabled, character_thresh, character_mcut_enabled], variant="secondary", size="lg")
with gr.Column():
sorted_general_strings = gr.Textbox(label="Output (string)")
rating = gr.Label(label="Rating")
character_res = gr.Label(label="Output (characters)")
general_res = gr.Label(label="Output (tags)")
clear_button.add([sorted_general_strings, rating, character_res, general_res])
submit_button.click(modules.wdtagger.predictor.predict, inputs=[image, model_repo, general_thresh, general_mcut_enabled, character_thresh, character_mcut_enabled], outputs=[sorted_general_strings, rating, character_res, general_res])
# Tab untuk Upscale
with gr.Tab("Upscale"):
with gr.Row():
with gr.Column():
input_image = gr.Image(type="pil", label="Input Image")
run_button = gr.Button("Enhance Image")
with gr.Row():
scheduler_name = gr.Dropdown(choices=schedulers, value=schedulers[0], label="Scheduler")
with gr.Row():
resolution = gr.Slider(minimum=128, maximum=2048, value=1024, step=128, label="Resolution")
num_inference_steps = gr.Slider(minimum=1, maximum=50, value=20, step=1, label="Number of Inference Steps")
with gr.Row():
hdr = gr.Slider(minimum=0, maximum=1, value=0, step=0.1, label="HDR Effect")
guidance_scale = gr.Slider(minimum=0, maximum=20, value=6, step=0.5, label="Guidance Scale")
with gr.Row():
strength = gr.Slider(minimum=0, maximum=1, value=0.2, step=0.01, label="Strength")
controlnet_strength = gr.Slider(minimum=0.0, maximum=2.0, value=0.75, step=0.05, label="ControlNet Strength")
with gr.Column():
output_slider = ImageSlider(label="Before / After", type="numpy")
run_button.click(fn=gradio_process_image, inputs=[input_image, resolution, num_inference_steps, strength, hdr, guidance_scale, controlnet_strength, scheduler_name], outputs=output_slider)
# Tab untuk About
with gr.Tab("About"):
with gr.Row():
gr.Markdown("""
# About
This user interface utilizes the **Diffusers** library to provide a comprehensive platform for generating and manipulating images. The interface is designed to be intuitive, allowing users to experiment with various image generation techniques and settings without needing deep technical knowledge.
**Gradio** is used to create this interactive web application. Gradio simplifies the integration of machine learning models into a web interface, offering a seamless experience for users.
## Describe
The "Describe" functionality is designed to help users create prompts for image generation. It is inspired by the [wd-tagger](https://huggingface.co/spaces/SmilingWolf/wd-tagger) space by SmilingWolf. This tool allows users to annotate and describe images using various models to generate detailed tags and descriptions.
With this feature, you can:
- Automatically generate descriptive tags for your images.
- Explore the potential tags and categories recognized by the model.
- Enhance the metadata of your images for better organization and searchability.
Visit the original [wd-tagger](https://huggingface.co/spaces/SmilingWolf/wd-tagger) for more details.
## Upscale
The "Upscale" feature enables users to improve the resolution of their images, making them clearer and more detailed. It is inspired by the [TileUpscalerV2](https://huggingface.co/spaces/gokaygokay/TileUpscalerV2) space by gokaygokay.
With this feature, you can:
- Increase the resolution of your generated images.
- Enhance the quality of images without losing important details.
- Make your images suitable for printing or high-resolution displays.
Visit the original [TileUpscalerV2](https://huggingface.co/spaces/gokaygokay/TileUpscalerV2) for more details.
## Contribute
We are always looking for passionate individuals who are interested in contributing to this project. Whether you're a developer, designer, or just someone with great ideas, your help is welcome!
This project is open-source and licensed under the **Apache 2.0** License. Contributions are voluntary and there is no financial compensation, but you will gain valuable experience and the satisfaction of knowing your work is helping to advance the field of machine learning and AI.
If you're interested in contributing, please get in touch with us. We appreciate any help you can provide!
### How to Contribute
1. Fork the repository on GitHub.
2. Create a new branch for your feature or bugfix.
3. Make your changes and commit them with clear messages.
4. Submit a pull request for review.
Thank you for considering contributing to our project!
""")
# Jalankan antarmuka
app.launch() |