primerz commited on
Commit
cc293c4
·
verified ·
1 Parent(s): 31c79b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -15
app.py CHANGED
@@ -13,13 +13,30 @@ gen = Generator(handler)
13
 
14
  # 2. Define GPU-enabled Inference Function
15
  @spaces.GPU(duration=35)
16
- def process_img(image, prompt):
 
 
 
 
 
 
 
 
17
  if image is None:
18
  raise gr.Error("Please upload an image first.")
19
 
20
  try:
21
  print("--- Starting Generation ---")
22
- result = gen.predict(image, prompt)
 
 
 
 
 
 
 
 
 
23
  print("--- Generation Complete ---")
24
  return result
25
 
@@ -37,7 +54,7 @@ with gr.Blocks(title="Face To Pixel Art", theme=gr.themes.Soft()) as demo:
37
  )
38
 
39
  with gr.Row():
40
- with gr.Column():
41
  input_img = gr.Image(type="pil", label="Input Image")
42
  prompt = gr.Textbox(
43
  label="Prompt (Optional)",
@@ -45,25 +62,81 @@ with gr.Blocks(title="Face To Pixel Art", theme=gr.themes.Soft()) as demo:
45
  info="The trigger words 'p1x3l4rt, pixel art' are added automatically."
46
  )
47
  run_btn = gr.Button("Generate Pixel Art", variant="primary")
48
-
49
- with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
50
  output_img = gr.Image(label="Pixel Art Result")
51
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  # Event Handler
 
 
 
 
 
 
 
 
 
 
 
53
  run_btn.click(
54
  fn=process_img,
55
- inputs=[input_img, prompt],
56
  outputs=[output_img]
57
  )
58
 
59
- gr.Examples(
60
- examples=[
61
- ["./examples/monalisa.jpg", "mona lisa portrait"],
62
- ["./examples/man.jpg", "photo of a man"],
63
- ["./examples/landscape.jpg", "a beautiful landscape"]
64
- ],
65
- inputs=[input_img, prompt]
66
- )
67
 
68
  # 4. Launch the App
69
  if __name__ == "__main__":
 
13
 
14
  # 2. Define GPU-enabled Inference Function
15
  @spaces.GPU(duration=35)
16
+ def process_img(
17
+ image,
18
+ prompt,
19
+ cfg_scale,
20
+ steps,
21
+ img_strength,
22
+ depth_strength,
23
+ edge_strength
24
+ ):
25
  if image is None:
26
  raise gr.Error("Please upload an image first.")
27
 
28
  try:
29
  print("--- Starting Generation ---")
30
+ # Pass all parameters to the generator
31
+ result = gen.predict(
32
+ image,
33
+ prompt,
34
+ guidance_scale=cfg_scale,
35
+ num_inference_steps=steps,
36
+ img2img_strength=img_strength,
37
+ depth_strength=depth_strength,
38
+ lineart_strength=edge_strength
39
+ )
40
  print("--- Generation Complete ---")
41
  return result
42
 
 
54
  )
55
 
56
  with gr.Row():
57
+ with gr.Column(scale=2):
58
  input_img = gr.Image(type="pil", label="Input Image")
59
  prompt = gr.Textbox(
60
  label="Prompt (Optional)",
 
62
  info="The trigger words 'p1x3l4rt, pixel art' are added automatically."
63
  )
64
  run_btn = gr.Button("Generate Pixel Art", variant="primary")
65
+
66
+ gr.Examples(
67
+ examples=[
68
+ # Add default values for new sliders
69
+ ["./examples/monalisa.jpg", "mona lisa portrait", 1.5, 6, 0.3, 0.3, 0.3],
70
+ ["./examples/man.jpg", "photo of a man", 1.5, 6, 0.3, 0.3, 0.3],
71
+ ["./examples/landscape.jpg", "a beautiful landscape", 1.5, 6, 0.3, 0.3, 0.3]
72
+ ],
73
+ # Update inputs to match the new sliders
74
+ inputs=[input_img, prompt, "cfg_scale", "steps", "img_strength", "depth_strength", "edge_strength"]
75
+ )
76
+
77
+ with gr.Column(scale=1):
78
  output_img = gr.Image(label="Pixel Art Result")
79
+
80
+ with gr.Accordion("Advanced Settings", open=False):
81
+ cfg_scale = gr.Slider(
82
+ elem_id="cfg_scale",
83
+ minimum=1.0,
84
+ maximum=5.0,
85
+ step=0.1,
86
+ value=1.5,
87
+ label="CFG Scale"
88
+ )
89
+ steps = gr.Slider(
90
+ elem_id="steps",
91
+ minimum=4,
92
+ maximum=20,
93
+ step=1,
94
+ value=6,
95
+ label="Steps Number"
96
+ )
97
+ img_strength = gr.Slider(
98
+ elem_id="img_strength",
99
+ minimum=0.1,
100
+ maximum=1.0,
101
+ step=0.05,
102
+ value=0.3,
103
+ label="Image Strength (Img2Img)"
104
+ )
105
+ depth_strength = gr.Slider(
106
+ elem_id="depth_strength",
107
+ minimum=0.0,
108
+ maximum=1.0,
109
+ step=0.05,
110
+ value=0.3,
111
+ label="DepthMap Strength"
112
+ )
113
+ edge_strength = gr.Slider(
114
+ elem_id="edge_strength",
115
+ minimum=0.0,
116
+ maximum=1.0,
117
+ step=0.05,
118
+ value=0.3,
119
+ label="EdgeMap Strength (LineArt)"
120
+ )
121
+
122
  # Event Handler
123
+ # Update inputs list for the click event
124
+ all_inputs = [
125
+ input_img,
126
+ prompt,
127
+ cfg_scale,
128
+ steps,
129
+ img_strength,
130
+ depth_strength,
131
+ edge_strength
132
+ ]
133
+
134
  run_btn.click(
135
  fn=process_img,
136
+ inputs=all_inputs,
137
  outputs=[output_img]
138
  )
139
 
 
 
 
 
 
 
 
 
140
 
141
  # 4. Launch the App
142
  if __name__ == "__main__":