Surn commited on
Commit
002e417
·
1 Parent(s): 93e5537

HURA Implementation

Browse files
Files changed (1) hide show
  1. app.py +51 -33
app.py CHANGED
@@ -747,8 +747,7 @@ def on_input_image_change(image_path):
747
  return None, gr.update()
748
  img, img_path = convert_to_rgba_png(image_path)
749
  width, height = img.size
750
- hex_components["set_height_width_hura_image"](width, height)
751
- return [img_path, gr.update(width=width, height=height)]
752
 
753
  def update_sketch_dimensions(input_image, sketch_image):
754
  # Load the images using open_image() if they are provided as file paths.
@@ -1268,6 +1267,7 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1268
  with gr.Row():
1269
  apply_lut_button = gr.Button("Apply Filter to Input Image", elem_classes="solid", elem_id="apply_lut_button")
1270
  apply_lut_to_sketch_button = gr.Button("Apply Filter to Sketch", elem_classes="solid", elem_id="apply_lut_to_sketch_button")
 
1271
  with gr.Row():
1272
  lut_example_image = gr.Image(type="pil", label="Filter (LUT) Example Image", value=constants.default_lut_example_img)
1273
  with gr.Row():
@@ -1285,35 +1285,21 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1285
  label="Select a Filter (LUT) file to populate the LUT File Name field",
1286
  examples_per_page = 25,
1287
  )
1288
-
1289
- lut_file.change(get_filename, inputs=[lut_file], outputs=[lut_filename])
1290
- lut_filename.change(show_lut, inputs=[lut_filename, input_image, lut_intensity], outputs=[lut_example_image], scroll_to_output=True)
1291
- lut_intensity.change(show_lut, inputs=[lut_filename, input_image, lut_intensity], outputs=[lut_example_image])
1292
- apply_lut_button.click(
1293
- lambda lut_filename, input_image, lut_intensity: gr.Warning("Please upload an Input Image to get started.") if input_image is None else apply_lut_to_image_path(lut_filename, input_image, lut_intensity)[1],
1294
- inputs=[lut_filename, input_image, lut_intensity],
1295
- outputs=[input_image],
1296
- scroll_to_output=True
1297
- )
1298
- apply_lut_to_sketch_button.click(
1299
- lambda lut_filename, sketch_image, lut_intensity: gr.Warning("Please upload an Input Image to get started.") if input_image is None else apply_lut_to_image_path(lut_filename, replace_with_sketch_image(sketch_image, False), lut_intensity)[1],
1300
- inputs=[lut_filename, sketch_image, lut_intensity],
1301
- outputs=[sketch_image],
1302
- scroll_to_output=True
1303
- )
1304
  with gr.Accordion("Color Composite", open = False):
1305
  with gr.Row():
1306
  composite_color = gr.ColorPicker(label="Color", value="#ede9ac44")
1307
  composite_opacity = gr.Slider(label="Opacity %", minimum=0, maximum=100, value=50, interactive=True)
1308
  with gr.Row():
1309
- composite_button = gr.Button("Composite to Input Image", elem_classes="solid")
1310
- composite_sketch_button = gr.Button("Composite to Sketh", elem_classes="solid")
 
1311
  with gr.Accordion("Blur", open = False):
1312
  with gr.Row():
1313
  blur_amount = gr.Slider(label="Blur Amount", minimum=0, maximum=100, value=5, interactive=True)
1314
  with gr.Row():
1315
  blur_button = gr.Button("Blur Input Image", elem_classes="solid")
1316
  blur_sketch_button = gr.Button("Blur Sketch", elem_classes="solid")
 
1317
  with gr.Accordion("Generate Hex Hura Background", open = False):
1318
  hex_components = hex_hura.render()
1319
  with gr.Row():
@@ -1621,7 +1607,7 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1621
  input_image.input(
1622
  fn=on_input_image_change,
1623
  inputs=[input_image],
1624
- outputs=[input_image,sketch_image], scroll_to_output=True,
1625
  )
1626
  ###################### sketchpad ############################
1627
  btn_sketch_alpha_composite.click(
@@ -1651,16 +1637,45 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1651
 
1652
  #################### model end ########################################
1653
  ########### special effects ###############
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1654
  composite_button.click(
1655
  fn=lambda input_image, composite_color, composite_opacity: gr.Warning("Please upload an Input Image to get started.") if input_image is None else change_color(input_image, composite_color, composite_opacity),
1656
  inputs=[input_image, composite_color, composite_opacity],
1657
  outputs=[input_image]
1658
  )
1659
  composite_sketch_button.click(
1660
- fn=lambda sketch_image, composite_color, composite_opacity: gr.Warning("Please upload an Sketch Image to get started.") if Sketch_image is None else change_color(sketch_image, composite_color, composite_opacity),
1661
  inputs=[sketch_image, composite_color, composite_opacity],
1662
  outputs=[sketch_image]
1663
  )
 
 
 
 
 
 
 
1664
  blur_button.click(
1665
  fn=lambda input_image, blur_amount: gr.Warning("Please upload an Input Image to get started.") if input_image is None else blur_image(input_image, blur_amount),
1666
  inputs=[input_image, blur_amount],
@@ -1669,7 +1684,10 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1669
  fn=lambda sketch_image, blur_amount: gr.Warning("Please upload an Sketch Image to get started.") if sketch_image is None else blur_image(sketch_image, blur_amount),
1670
  inputs=[sketch_image, blur_amount],
1671
  outputs=[sketch_image])
1672
-
 
 
 
1673
  ################ end special effects ############################
1674
  #use conditioned_image as the input_image for generate_input_image_click
1675
  generate_input_image_from_gallery.click(
@@ -1704,31 +1722,31 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1704
  outputs=[sketch_image, sketch_image]
1705
  )
1706
 
1707
- output_grid_tilt.change(
1708
  fn=transform_grid,
1709
  inputs=[output_image, output_grid_tilt, output_grid_rotation],
1710
- outputs=[output_image]
1711
  )
1712
- output_grid_rotation.change(
1713
  fn=transform_grid,
1714
  inputs=[output_image, output_grid_tilt, output_grid_rotation],
1715
- outputs=[output_image]
1716
  )
1717
- output_overlay_composite.change(
1718
  fn=combine_images_with_lerp,
1719
  inputs=[input_image, output_image, output_overlay_composite],
1720
- outputs=[overlay_image], scroll_to_output=True
1721
  )
1722
- output_blend_multiply_composite.change(
1723
  fn=multiply_and_blend_images,
1724
  inputs=[input_image, output_image, output_blend_multiply_composite],
1725
- outputs=[overlay_image],
1726
  scroll_to_output=True
1727
  )
1728
- output_alpha_composite.change(
1729
  fn=alpha_composite_with_control,
1730
  inputs=[input_image, output_image, output_alpha_composite],
1731
- outputs=[overlay_image],
1732
  scroll_to_output=True
1733
  )
1734
  add_border_button.click(
 
747
  return None, gr.update()
748
  img, img_path = convert_to_rgba_png(image_path)
749
  width, height = img.size
750
+ return [img_path, gr.update(width=width, height=height), gr.update(value=width), gr.update(value=height)]
 
751
 
752
  def update_sketch_dimensions(input_image, sketch_image):
753
  # Load the images using open_image() if they are provided as file paths.
 
1267
  with gr.Row():
1268
  apply_lut_button = gr.Button("Apply Filter to Input Image", elem_classes="solid", elem_id="apply_lut_button")
1269
  apply_lut_to_sketch_button = gr.Button("Apply Filter to Sketch", elem_classes="solid", elem_id="apply_lut_to_sketch_button")
1270
+ apply_lut_to_hura_button = gr.Button("Apply Filter to HURA", elem_classes="solid", elem_id="apply_lut_to_hura_button")
1271
  with gr.Row():
1272
  lut_example_image = gr.Image(type="pil", label="Filter (LUT) Example Image", value=constants.default_lut_example_img)
1273
  with gr.Row():
 
1285
  label="Select a Filter (LUT) file to populate the LUT File Name field",
1286
  examples_per_page = 25,
1287
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1288
  with gr.Accordion("Color Composite", open = False):
1289
  with gr.Row():
1290
  composite_color = gr.ColorPicker(label="Color", value="#ede9ac44")
1291
  composite_opacity = gr.Slider(label="Opacity %", minimum=0, maximum=100, value=50, interactive=True)
1292
  with gr.Row():
1293
+ composite_button = gr.Button("Composite to Input Image", elem_classes="solid", elem_id="composite_to_input_button")
1294
+ composite_sketch_button = gr.Button("Composite to Sketh", elem_classes="solid", elem_id="composite_to_sketch_button")
1295
+ composite_hura_button = gr.Button("Composite to HURA", elem_classes="solid", elem_id="composite_to_hura_button")
1296
  with gr.Accordion("Blur", open = False):
1297
  with gr.Row():
1298
  blur_amount = gr.Slider(label="Blur Amount", minimum=0, maximum=100, value=5, interactive=True)
1299
  with gr.Row():
1300
  blur_button = gr.Button("Blur Input Image", elem_classes="solid")
1301
  blur_sketch_button = gr.Button("Blur Sketch", elem_classes="solid")
1302
+ blur_hura_button = gr.Button("Blur HURA", elem_classes="solid")
1303
  with gr.Accordion("Generate Hex Hura Background", open = False):
1304
  hex_components = hex_hura.render()
1305
  with gr.Row():
 
1607
  input_image.input(
1608
  fn=on_input_image_change,
1609
  inputs=[input_image],
1610
+ outputs=[input_image, sketch_image, hex_components["width_slider"], hex_components["height_slider"]], scroll_to_output=True,
1611
  )
1612
  ###################### sketchpad ############################
1613
  btn_sketch_alpha_composite.click(
 
1637
 
1638
  #################### model end ########################################
1639
  ########### special effects ###############
1640
+ lut_file.change(get_filename, inputs=[lut_file], outputs=[lut_filename])
1641
+ lut_filename.change(show_lut, inputs=[lut_filename, input_image, lut_intensity], outputs=[lut_example_image], scroll_to_output=True)
1642
+ lut_intensity.release(show_lut, inputs=[lut_filename, input_image, lut_intensity], outputs=[lut_example_image], queue=False)
1643
+ apply_lut_button.click(
1644
+ lambda lut_filename, input_image, lut_intensity: gr.Warning("Please upload an Input Image to get started.") if input_image is None else apply_lut_to_image_path(lut_filename, input_image, lut_intensity)[1],
1645
+ inputs=[lut_filename, input_image, lut_intensity],
1646
+ outputs=[input_image],
1647
+ scroll_to_output=True
1648
+ )
1649
+ apply_lut_to_sketch_button.click(
1650
+ lambda lut_filename, sketch_image, lut_intensity: gr.Warning("Please upload an Input Image to get started.") if input_image is None else apply_lut_to_image_path(lut_filename, replace_with_sketch_image(sketch_image, False), lut_intensity)[1],
1651
+ inputs=[lut_filename, sketch_image, lut_intensity],
1652
+ outputs=[sketch_image],
1653
+ scroll_to_output=True
1654
+ )
1655
+ apply_lut_to_hura_button.click(
1656
+ lambda lut_filename, hura_image, lut_intensity: gr.Warning("Please create a HURA to get started.") if hex_components["target_image"] is None else apply_lut_to_image_path(lut_filename, hura_image, lut_intensity)[1],
1657
+ inputs=[lut_filename, hex_components["target_image"], lut_intensity],
1658
+ outputs=hex_components["target_image"],
1659
+ scroll_to_output=True
1660
+ )
1661
+
1662
  composite_button.click(
1663
  fn=lambda input_image, composite_color, composite_opacity: gr.Warning("Please upload an Input Image to get started.") if input_image is None else change_color(input_image, composite_color, composite_opacity),
1664
  inputs=[input_image, composite_color, composite_opacity],
1665
  outputs=[input_image]
1666
  )
1667
  composite_sketch_button.click(
1668
+ fn=lambda sketch_image, composite_color, composite_opacity: gr.Warning("Please upload an Sketch Image to get started.") if sketch_image is None else change_color(sketch_image, composite_color, composite_opacity),
1669
  inputs=[sketch_image, composite_color, composite_opacity],
1670
  outputs=[sketch_image]
1671
  )
1672
+ composite_hura_button.click(
1673
+ fn=lambda hura_image, composite_color, composite_opacity: gr.Warning("Please create a HURA to get started.") if hex_components["target_image"] is None else change_color(hura_image, composite_color, composite_opacity),
1674
+ inputs=[ hex_components["target_image"], composite_color, composite_opacity],
1675
+ outputs=hex_components["target_image"],
1676
+ scroll_to_output=True
1677
+ )
1678
+
1679
  blur_button.click(
1680
  fn=lambda input_image, blur_amount: gr.Warning("Please upload an Input Image to get started.") if input_image is None else blur_image(input_image, blur_amount),
1681
  inputs=[input_image, blur_amount],
 
1684
  fn=lambda sketch_image, blur_amount: gr.Warning("Please upload an Sketch Image to get started.") if sketch_image is None else blur_image(sketch_image, blur_amount),
1685
  inputs=[sketch_image, blur_amount],
1686
  outputs=[sketch_image])
1687
+ blur_hura_button.click(
1688
+ fn=lambda hura_image, blur_amount: gr.Warning("Please create a HURA to get started.") if hex_components["target_image"] is None else blur_image(hura_image, blur_amount),
1689
+ inputs=[hex_components["target_image"], blur_amount],
1690
+ outputs=[hex_components["target_image"]])
1691
  ################ end special effects ############################
1692
  #use conditioned_image as the input_image for generate_input_image_click
1693
  generate_input_image_from_gallery.click(
 
1722
  outputs=[sketch_image, sketch_image]
1723
  )
1724
 
1725
+ output_grid_tilt.release(
1726
  fn=transform_grid,
1727
  inputs=[output_image, output_grid_tilt, output_grid_rotation],
1728
+ outputs=[output_image], queue=False
1729
  )
1730
+ output_grid_rotation.release(
1731
  fn=transform_grid,
1732
  inputs=[output_image, output_grid_tilt, output_grid_rotation],
1733
+ outputs=[output_image], queue=False
1734
  )
1735
+ output_overlay_composite.release(
1736
  fn=combine_images_with_lerp,
1737
  inputs=[input_image, output_image, output_overlay_composite],
1738
+ outputs=[overlay_image], queue=False, scroll_to_output=True
1739
  )
1740
+ output_blend_multiply_composite.release(
1741
  fn=multiply_and_blend_images,
1742
  inputs=[input_image, output_image, output_blend_multiply_composite],
1743
+ outputs=[overlay_image], queue=False,
1744
  scroll_to_output=True
1745
  )
1746
+ output_alpha_composite.release(
1747
  fn=alpha_composite_with_control,
1748
  inputs=[input_image, output_image, output_alpha_composite],
1749
+ outputs=[overlay_image], queue=False,
1750
  scroll_to_output=True
1751
  )
1752
  add_border_button.click(