Spaces:
Sleeping
Sleeping
File size: 10,843 Bytes
0926cd3 c1254e9 e9ed267 0926cd3 e9ed267 0926cd3 e9ed267 6e0fda9 e9ed267 cecd5f5 0926cd3 cecd5f5 01a3261 6e0fda9 0926cd3 01a3261 c1254e9 be9cced e9ed267 0926cd3 cecd5f5 0926cd3 01a3261 0926cd3 e9ed267 01a3261 e9ed267 cecd5f5 e9ed267 0926cd3 e9ed267 cecd5f5 e9ed267 0926cd3 01a3261 0926cd3 01a3261 0926cd3 01a3261 0926cd3 01a3261 0926cd3 01a3261 0926cd3 c1254e9 0926cd3 c1254e9 01a3261 c1254e9 01a3261 be9cced 0926cd3 01a3261 0926cd3 c1254e9 0926cd3 c1254e9 0926cd3 c1254e9 01a3261 cecd5f5 0926cd3 cecd5f5 01a3261 e9ed267 cecd5f5 c1254e9 01a3261 cecd5f5 a8949bc 01a3261 a8949bc 01a3261 0926cd3 a8949bc 01a3261 a8949bc 01a3261 a8949bc cecd5f5 01a3261 be9cced 01a3261 be9cced 01a3261 be9cced cecd5f5 e9ed267 0926cd3 e9ed267 01a3261 e9ed267 8ec1561 e9ed267 cecd5f5 0926cd3 be9cced 01a3261 be9cced 01a3261 be9cced cecd5f5 e9ed267 01a3261 cecd5f5 0926cd3 e9ed267 01a3261 e9ed267 cecd5f5 0926cd3 be9cced 01a3261 be9cced 01a3261 be9cced e9ed267 cecd5f5 e9ed267 01a3261 e9ed267 0926cd3 e9ed267 01a3261 e9ed267 cecd5f5 0926cd3 cecd5f5 0926cd3 01a3261 5c88e58 c1254e9 01a3261 ab8d95b 01a3261 6e0fda9 01a3261 6e0fda9 c1254e9 6e0fda9 01a3261 c1254e9 01a3261 0926cd3 01a3261 c1254e9 01a3261 c1254e9 01a3261 0abb49c 01a3261 0abb49c c1254e9 be9cced 90138e7 be9cced | 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | """Driver File."""
import gradio as gr
import core
import parameters
############################################ LAYOUT ############################################
with gr.Blocks() as demo:
# ... [previous state variables remain the same] ...
selected_image = gr.State(None)
current_episode = gr.State(-1)
current_scene = gr.State(-1)
current_frame = gr.State(-1)
episode_data = gr.State({})
character_data = gr.State({})
current_frame_data = gr.State(None)
frame_hash_map = gr.State({})
image_data_b64 = gr.State([])
choice = gr.State([])
with gr.Row():
with gr.Column():
comic_id = gr.Textbox(label="Enter Comic ID:", placeholder="Enter Comic ID")
load_metadata = gr.Button("Load Metadata")
# Display information about current Image
with gr.Row():
episode_dropdown = gr.Dropdown(
choices=[], label="Current Episode", interactive=True
)
frame_dropdown = gr.Dropdown(
choices=[], label="Current Frame", interactive=True
)
with gr.Column():
load_images = gr.Button("Load Images")
developer = gr.Checkbox(
value=False, label="Enable Developer Mode"
)
images = gr.Gallery(
label="Select an Image", elem_id="image_select", columns=4, height=320, object_fit="contain"
)
with gr.Row():
image_description = gr.Textbox(label="Description", interactive=False)
narration = gr.Textbox(label="narration", interactive=False)
with gr.Row():
character = gr.Textbox(label="Character", interactive=False)
dialouge = gr.Textbox(label="Dialouge", interactive=False)
location = gr.Textbox(label="Location", interactive=False)
# buttons to interact with the data
with gr.Row():
prev_button = gr.Button("Prev Image")
save_button = gr.Button("Save Image")
next_button = gr.Button("Next Image")
with gr.Column(visible=False) as developer_options:
with gr.Column():
setting = gr.Textbox(label="Frame Setting", interactive=True)
with gr.Row():
with gr.Column():
gr.Markdown("## Composition #1")
prompt_1 = gr.TextArea(label="Image Prompt", interactive=True)
seed_1 = gr.Textbox(label="Generation Seed")
with gr.Column():
gr.Markdown("## Composition #2")
prompt_2 = gr.TextArea(label="Image Prompt", interactive=True)
seed_2 = gr.Textbox(label="Generation Seed")
with gr.Row():
with gr.Column():
gr.Markdown("## Composition #3")
prompt_3 = gr.TextArea(label="Image Prompt", interactive=True)
seed_3 = gr.Textbox(label="Generation Seed")
with gr.Column():
gr.Markdown("## Composition #4")
prompt_4 = gr.TextArea(label="Image Prompt", interactive=True)
seed_4 = gr.Textbox(label="Generation Seed")
with gr.Row():
regenerate_comps_btn = gr.Button(value="Regenerate Compositions")
with gr.Column():
negative_prompt = gr.TextArea(
value="",
label="Negative Prompt",
interactive=True,
)
related_chars = gr.CheckboxGroup(
choices=[], value=[], label="Related Characters", interactive=True
)
with gr.Row():
height = gr.Textbox(
value=parameters.IMG_HEIGHT, label="Image Height", interactive=True
)
width = gr.Textbox(
value=parameters.IMG_WIDTH, label="Image Width", interactive=True
)
visual_style = gr.Dropdown(
choices=parameters.VISUAL_CHOICES,
label="Current Visual Style",
interactive=True,
)
with gr.Row():
regenerate_btn = gr.Button("Regenerate")
save_btn = gr.Button("Save")
############################################ EVENTS ############################################
developer.change(
core.toggle_developer_options,
inputs=[developer],
outputs=[developer_options],
).then(
lambda is_developer: (
gr.update(interactive=is_developer),
gr.update(interactive=is_developer),
gr.update(interactive=is_developer),
gr.update(interactive=is_developer),
gr.update(interactive=is_developer),
),
inputs=[developer],
outputs=[image_description, narration, character, dialouge, location],
)
load_metadata.click(
core.load_metadata_fn,
inputs=[comic_id],
outputs=[episode_dropdown, current_episode, character_data],
).then( # This ensures `load_dropdown_fn` runs after `load_metadata_fn`
core.episode_dropdown_effect,
inputs=[comic_id, episode_dropdown],
outputs=[
frame_dropdown,
current_episode,
current_frame,
episode_data,
frame_hash_map,
],
)
episode_dropdown.input(
core.episode_dropdown_effect,
inputs=[comic_id, episode_dropdown],
outputs=[
frame_dropdown,
current_episode,
current_frame,
episode_data,
frame_hash_map,
],
)
frame_dropdown.input(
lambda frame: frame,
inputs=[frame_dropdown],
outputs=[current_frame],
)
load_images.click(
core.load_data,
inputs=[
episode_data,
current_frame,
frame_hash_map,
],
outputs=[
images,
image_description,
narration,
character,
dialouge,
location,
setting,
prompt_1,
seed_1,
prompt_2,
seed_2,
prompt_3,
seed_3,
prompt_4,
seed_4,
],
).then(
core.update_characters,
inputs=[character_data, current_frame, frame_hash_map, episode_data],
outputs=[related_chars],
)
# When an image is clicked
def get_select_index(evt: gr.SelectData, images):
return images[evt.index]
images.select(get_select_index, images, selected_image)
next_button.click(
core.load_data_next,
inputs=[
comic_id,
current_episode,
current_frame,
frame_hash_map,
episode_data,
],
outputs=[
episode_dropdown,
frame_dropdown,
current_episode,
current_frame,
episode_data,
frame_hash_map,
],
).then(
core.load_data,
inputs=[
episode_data,
current_frame,
frame_hash_map,
],
outputs=[
images,
image_description,
narration,
character,
dialouge,
location,
setting,
prompt_1,
seed_1,
prompt_2,
seed_2,
prompt_3,
seed_3,
prompt_4,
seed_4,
],
).then(
core.update_characters,
inputs=[character_data, current_frame, frame_hash_map, episode_data],
outputs=[related_chars],
).then(
lambda a, b: (a, b),
inputs=[current_episode, current_frame],
outputs=[current_episode, current_frame],
)
prev_button.click(
core.load_data_prev,
inputs=[
comic_id,
current_episode,
current_frame,
frame_hash_map,
episode_data,
],
outputs=[
episode_dropdown,
frame_dropdown,
current_episode,
current_frame,
episode_data,
frame_hash_map,
],
).then(
core.load_data,
inputs=[
episode_data,
current_frame,
frame_hash_map,
],
outputs=[
images,
image_description,
narration,
character,
dialouge,
location,
setting,
prompt_1,
seed_1,
prompt_2,
seed_2,
prompt_3,
seed_3,
prompt_4,
seed_4,
],
).then(
core.update_characters,
inputs=[character_data, current_frame, frame_hash_map, episode_data],
outputs=[related_chars],
).then(
lambda a, b: (a, b),
inputs=[current_episode, current_frame],
outputs=[current_episode, current_frame],
)
save_button.click(
core.save_image,
inputs=[
selected_image,
comic_id,
current_episode,
current_frame,
],
outputs=[],
)
regenerate_comps_btn.click(
core.regenerate_compositions,
inputs=[
image_description,
narration,
character,
dialouge,
location,
setting,
related_chars,
current_episode,
current_frame,
episode_data,
frame_hash_map,
character_data,
],
outputs=[
prompt_1,
prompt_2,
prompt_3,
prompt_4,
],
)
regenerate_btn.click(
core.regenerate_images,
inputs=[
current_episode,
current_frame,
visual_style,
height,
width,
character_data,
related_chars,
prompt_1,
seed_1,
prompt_2,
seed_2,
prompt_3,
seed_3,
prompt_4,
seed_4
],
outputs=[images],
)
save_btn.click(
core.save_comic_data,
inputs=[
current_episode,
current_frame,
episode_data,
comic_id,
image_description,
narration,
character,
dialouge,
location,
setting,
prompt_1,
prompt_2,
prompt_3,
prompt_4,
frame_hash_map,
related_chars,
character_data,
images,
]
)
demo.launch(
auth=("admin", "Qrt@12*34#immersfy"), share=True, ssr_mode=False, debug=True
)
|