Spaces:
Running
Running
Add Clarity option
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ def get_flux_image(prompt):
|
|
22 |
print(result)
|
23 |
return result[0]
|
24 |
|
25 |
-
def
|
26 |
client = Client("finegrain/finegrain-image-enhancer")
|
27 |
result = client.predict(
|
28 |
input_image=handle_file(img_path),
|
@@ -43,11 +43,42 @@ def get_upscale(prompt, img_path, upscale_factor):
|
|
43 |
print(result)
|
44 |
return result[1]
|
45 |
|
46 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
step_one_flux = get_flux_image(prompt)
|
48 |
-
|
|
|
|
|
|
|
49 |
return (step_one_flux, step_two_upscale)
|
50 |
|
|
|
|
|
|
|
51 |
css = """
|
52 |
#col-container{
|
53 |
margin: 0 auto;
|
@@ -57,7 +88,7 @@ css = """
|
|
57 |
with gr.Blocks(css=css) as demo:
|
58 |
with gr.Column(elem_id="col-container"):
|
59 |
gr.Markdown("# Flux Upscaled")
|
60 |
-
gr.Markdown("Step 1: Generate image with FLUX schnell; Step 2: UpScale with
|
61 |
with gr.Group():
|
62 |
prompt_in = gr.Textbox(label="Prompt")
|
63 |
with gr.Row():
|
@@ -68,23 +99,33 @@ with gr.Blocks(css=css) as demo:
|
|
68 |
],
|
69 |
value = 2
|
70 |
)
|
|
|
|
|
|
|
|
|
|
|
71 |
submit_btn = gr.Button("Submit")
|
72 |
output_res = ImageSlider(label="Flux / Upscaled")
|
73 |
|
74 |
gr.Examples(
|
75 |
examples = [
|
76 |
-
["a tiny astronaut hatching from an egg on the moon", 2],
|
77 |
-
["a bright blue bird in the garden, natural photo cinematic, MM full HD", 2]
|
78 |
],
|
79 |
fn = main,
|
80 |
-
inputs=[prompt_in, upscale_factor],
|
81 |
outputs=[output_res],
|
82 |
cache_examples = "lazy"
|
83 |
)
|
84 |
|
85 |
submit_btn.click(
|
|
|
|
|
|
|
|
|
|
|
86 |
fn=main,
|
87 |
-
inputs=[prompt_in, upscale_factor],
|
88 |
outputs=[output_res],
|
89 |
|
90 |
)
|
|
|
22 |
print(result)
|
23 |
return result[0]
|
24 |
|
25 |
+
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
26 |
client = Client("finegrain/finegrain-image-enhancer")
|
27 |
result = client.predict(
|
28 |
input_image=handle_file(img_path),
|
|
|
43 |
print(result)
|
44 |
return result[1]
|
45 |
|
46 |
+
def get_clarity_upscale(prompt, img_path, upscale_factor):
|
47 |
+
client = Client("jbilcke-hf/clarity-upscaler")
|
48 |
+
result = client.predict(
|
49 |
+
img_path, # filepath in 'Image' Image component
|
50 |
+
prompt, # str in 'Prompt' Textbox component
|
51 |
+
"", # str in 'Negative Prompt' Textbox component
|
52 |
+
scale_factor, # float in 'Scale Factor' Number component
|
53 |
+
1, # float (numeric value between 1 and 50) in 'Dynamic' Slider component
|
54 |
+
3, # float in 'Creativity' Number component
|
55 |
+
3, # float in 'Resemblance' Number component
|
56 |
+
"16", # Literal['16', '32', '48', '64', '80', '96', '112', '128', '144', '160', '176', '192', '208', '224', '240', '256'] in 'tiling_width' Dropdown component
|
57 |
+
"16", # Literal['16', '32', '48', '64', '80', '96', '112', '128', '144', '160', '176', '192', '208', '224', '240', '256'] in 'tiling_height' Dropdown component
|
58 |
+
"epicrealism_naturalSinRC1VAE.safetensors [84d76a0328]", # Literal['epicrealism_naturalSinRC1VAE.safetensors [84d76a0328]', 'juggernaut_reborn.safetensors [338b85bc4f]', 'flat2DAnimerge_v45Sharp.safetensors'] in 'sd_model' Dropdown component
|
59 |
+
"DPM++ 2M Karras", # Literal['DPM++ 2M Karras', 'DPM++ SDE Karras', 'DPM++ 2M SDE Exponential', 'DPM++ 2M SDE Karras', 'Euler a', 'Euler', 'LMS', 'Heun', 'DPM2', 'DPM2 a', 'DPM++ 2S a', 'DPM++ 2M', 'DPM++ SDE', 'DPM++ 2M SDE', 'DPM++ 2M SDE Heun', 'DPM++ 2M SDE Heun Karras', 'DPM++ 2M SDE Heun Exponential', 'DPM++ 3M SDE', 'DPM++ 3M SDE Karras', 'DPM++ 3M SDE Exponential', 'DPM fast', 'DPM adaptive', 'LMS Karras', 'DPM2 Karras', 'DPM2 a Karras', 'DPM++ 2S a Karras', 'Restart', 'DDIM', 'PLMS', 'UniPC'] in 'scheduler' Dropdown component
|
60 |
+
1, # float (numeric value between 1 and 100) in 'Num Inference Steps' Slider component
|
61 |
+
3, # float in 'Seed' Number component
|
62 |
+
True, # bool in 'Downscaling' Checkbox component
|
63 |
+
3, # float in 'Downscaling Resolution' Number component
|
64 |
+
"Hello!!", # str in 'Lora Links' Textbox component
|
65 |
+
"Hello!!", # str in 'Custom Sd Model' Textbox component
|
66 |
+
api_name="/predict"
|
67 |
+
)
|
68 |
+
print(result)
|
69 |
+
return result
|
70 |
+
|
71 |
+
def main(prompt, upscale_factor, upscale_provider):
|
72 |
step_one_flux = get_flux_image(prompt)
|
73 |
+
if upscale_provider == "finegrain image enhancer":
|
74 |
+
step_two_upscale = get_upscale_finegrain(prompt, step_one_flux, upscale_factor)
|
75 |
+
elif upscale_provider == "clarity upscale":
|
76 |
+
step_two_upscale = get_clarity_upscale(prompt, step_one_flux, upscale_factor)
|
77 |
return (step_one_flux, step_two_upscale)
|
78 |
|
79 |
+
def clean_previous():
|
80 |
+
return gr.update(value=None)
|
81 |
+
|
82 |
css = """
|
83 |
#col-container{
|
84 |
margin: 0 auto;
|
|
|
88 |
with gr.Blocks(css=css) as demo:
|
89 |
with gr.Column(elem_id="col-container"):
|
90 |
gr.Markdown("# Flux Upscaled")
|
91 |
+
gr.Markdown("Step 1: Generate image with FLUX schnell; Step 2: UpScale with Finegrain Image-Enhancer OR Clarity UpScale;")
|
92 |
with gr.Group():
|
93 |
prompt_in = gr.Textbox(label="Prompt")
|
94 |
with gr.Row():
|
|
|
99 |
],
|
100 |
value = 2
|
101 |
)
|
102 |
+
upscale_provider = gr.Dropdown(
|
103 |
+
label = "UpScale Provider",
|
104 |
+
choices = ["finegrain image enhancer", "clarity upscale"],
|
105 |
+
value = "clarity upscale"
|
106 |
+
)
|
107 |
submit_btn = gr.Button("Submit")
|
108 |
output_res = ImageSlider(label="Flux / Upscaled")
|
109 |
|
110 |
gr.Examples(
|
111 |
examples = [
|
112 |
+
["a tiny astronaut hatching from an egg on the moon", 2, "clarity upscale"],
|
113 |
+
["a bright blue bird in the garden, natural photo cinematic, MM full HD", 2, "clarity_upscale"]
|
114 |
],
|
115 |
fn = main,
|
116 |
+
inputs=[prompt_in, upscale_factor, upscale_provider],
|
117 |
outputs=[output_res],
|
118 |
cache_examples = "lazy"
|
119 |
)
|
120 |
|
121 |
submit_btn.click(
|
122 |
+
fn = clean_previous,
|
123 |
+
inputs = None,
|
124 |
+
outputs = [outputs_res],
|
125 |
+
queue=False
|
126 |
+
).then(
|
127 |
fn=main,
|
128 |
+
inputs=[prompt_in, upscale_factor, upscale_provider],
|
129 |
outputs=[output_res],
|
130 |
|
131 |
)
|