artificialguybr commited on
Commit
404edfc
1 Parent(s): d88a29b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -10
app.py CHANGED
@@ -8,16 +8,16 @@ import logging
8
  import time
9
  from tqdm import tqdm
10
 
11
- # Import additional modules
12
- from pixelart import Script as PixelArtScript
13
- from postprocessing_pixelart import ScriptPostprocessingUpscale
14
- from utils import downscale_image, limit_colors, resize_image, convert_to_grayscale, convert_to_black_and_white
15
-
16
  # Placeholder class for processed images
17
  class SomeClass:
18
  def __init__(self):
19
  self.images = []
20
 
 
 
 
 
 
21
  with open('loras.json', 'r') as f:
22
  loras = json.load(f)
23
 
@@ -65,6 +65,23 @@ def run_lora(prompt, selected_state, pixel_art_options, postprocess_options, pro
65
 
66
  return original_image, refined_image
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  with gr.Blocks() as app:
69
  title = gr.Markdown("# artificialguybr LoRA portfolio")
70
  description = gr.Markdown("### This is a Pixel Art Generator using SD Loras.")
@@ -87,12 +104,31 @@ with gr.Blocks() as app:
87
  button = gr.Button("Run")
88
 
89
  result = gr.Image(interactive=False, label="Generated Image")
90
- refined_result = gr.Image(interactive=False, label="Refined Generated Image") # New Output
 
 
 
91
 
92
  # New UI elements for pixel art options
93
  with gr.Row():
94
  pixel_art_options = PixelArtScript().ui(True)
95
  postprocess_options = ScriptPostprocessingUpscale().ui()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  gallery.select(
98
  update_selection,
@@ -105,10 +141,10 @@ with gr.Blocks() as app:
105
  outputs=[result, refined_result]
106
  )
107
 
108
- button.click(
109
- fn=run_lora,
110
- inputs=[prompt, selected_state, pixel_art_options, postprocess_options],
111
- outputs=[result, refined_result]
112
  )
113
 
114
  app.queue(max_size=20, concurrency_count=5)
 
8
  import time
9
  from tqdm import tqdm
10
 
 
 
 
 
 
11
  # Placeholder class for processed images
12
  class SomeClass:
13
  def __init__(self):
14
  self.images = []
15
 
16
+ # Import your existing modules
17
+ from pixelart import Script as PixelArtScript
18
+ from postprocessing_pixelart import ScriptPostprocessingUpscale
19
+ from utils import downscale_image, limit_colors, resize_image, convert_to_grayscale, convert_to_black_and_white
20
+
21
  with open('loras.json', 'r') as f:
22
  loras = json.load(f)
23
 
 
65
 
66
  return original_image, refined_image
67
 
68
+ def apply_post_processing(image, image_processing_options):
69
+ processed_image = image.copy()
70
+
71
+ if image_processing_options['downscale'] > 1:
72
+ processed_image = downscale_image(processed_image, image_processing_options['downscale'])
73
+
74
+ if image_processing_options['limit_colors']:
75
+ processed_image = limit_colors(processed_image)
76
+
77
+ if image_processing_options['grayscale']:
78
+ processed_image = convert_to_grayscale(processed_image)
79
+
80
+ if image_processing_options['black_and_white']:
81
+ processed_image = convert_to_black_and_white(processed_image)
82
+
83
+ return processed_image
84
+
85
  with gr.Blocks() as app:
86
  title = gr.Markdown("# artificialguybr LoRA portfolio")
87
  description = gr.Markdown("### This is a Pixel Art Generator using SD Loras.")
 
104
  button = gr.Button("Run")
105
 
106
  result = gr.Image(interactive=False, label="Generated Image")
107
+ refined_result = gr.Image(interactive=False, label="Refined Generated Image")
108
+
109
+ # New Output for Post-Processed Image
110
+ post_processed_result = gr.Image(interactive=False, label="Post-Processed Image")
111
 
112
  # New UI elements for pixel art options
113
  with gr.Row():
114
  pixel_art_options = PixelArtScript().ui(True)
115
  postprocess_options = ScriptPostprocessingUpscale().ui()
116
+
117
+ # New UI elements for image processing options
118
+ with gr.Row():
119
+ downscale = gr.Slider(minimum=1, maximum=10, step=1, label="Downscale")
120
+ limit_colors = gr.Checkbox(label="Limit Colors")
121
+ grayscale = gr.Checkbox(label="Grayscale")
122
+ black_and_white = gr.Checkbox(label="Black and White")
123
+
124
+ image_processing_options = {
125
+ 'downscale': downscale,
126
+ 'limit_colors': limit_colors,
127
+ 'grayscale': grayscale,
128
+ 'black_and_white': black_and_white
129
+ }
130
+
131
+ post_process_button = gr.Button("Apply Post-Processing")
132
 
133
  gallery.select(
134
  update_selection,
 
141
  outputs=[result, refined_result]
142
  )
143
 
144
+ post_process_button.click(
145
+ fn=apply_post_processing,
146
+ inputs=[refined_result, image_processing_options],
147
+ outputs=[post_processed_result]
148
  )
149
 
150
  app.queue(max_size=20, concurrency_count=5)