Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client, handle_file
|
| 3 |
+
|
| 4 |
+
def get_flux_image(prompt):
|
| 5 |
+
client = Client("black-forest-labs/FLUX.1-schnell")
|
| 6 |
+
result = client.predict(
|
| 7 |
+
prompt=prompt,
|
| 8 |
+
seed=0,
|
| 9 |
+
randomize_seed=True,
|
| 10 |
+
width=1024,
|
| 11 |
+
height=1024,
|
| 12 |
+
num_inference_steps=4,
|
| 13 |
+
api_name="/infer"
|
| 14 |
+
)
|
| 15 |
+
print(result)
|
| 16 |
+
return result[0]
|
| 17 |
+
|
| 18 |
+
def get_upscale(prompt, img_path):
|
| 19 |
+
client = Client("finegrain/finegrain-image-enhancer")
|
| 20 |
+
result = client.predict(
|
| 21 |
+
input_image=handle_file(img_path),
|
| 22 |
+
prompt=prompt,
|
| 23 |
+
negative_prompt="",
|
| 24 |
+
seed=42,
|
| 25 |
+
upscale_factor=2,
|
| 26 |
+
controlnet_scale=0.6,
|
| 27 |
+
controlnet_decay=1,
|
| 28 |
+
condition_scale=6,
|
| 29 |
+
tile_width=112,
|
| 30 |
+
tile_height=144,
|
| 31 |
+
denoise_strength=0.35,
|
| 32 |
+
num_inference_steps=18,
|
| 33 |
+
solver="DDIM",
|
| 34 |
+
api_name="/process"
|
| 35 |
+
)
|
| 36 |
+
print(result)
|
| 37 |
+
return result[0]
|
| 38 |
+
|
| 39 |
+
def main(prompt):
|
| 40 |
+
step_one_flux = get_flux_image(prompt)
|
| 41 |
+
step_two_upscale = get_upscale(prompt, step_one_flux)
|
| 42 |
+
return step_two_upscale
|
| 43 |
+
|
| 44 |
+
css = """
|
| 45 |
+
#col-container{
|
| 46 |
+
margin: 0 auto;
|
| 47 |
+
max-width: 1024px;
|
| 48 |
+
}
|
| 49 |
+
"""
|
| 50 |
+
with gr.Blocks(css=css) as demo:
|
| 51 |
+
with gr.Column(elem_id="col-container"):
|
| 52 |
+
gr.Markdown("Flux Upscaled")
|
| 53 |
+
prompt_in = gr.Textbox(label="Prompt")
|
| 54 |
+
submit_btn = gr.Button("Submit")
|
| 55 |
+
output_res = gr.Image(label="Result")
|
| 56 |
+
|
| 57 |
+
submit_btn.click(
|
| 58 |
+
fn=main,
|
| 59 |
+
inputs=[prompt_in],
|
| 60 |
+
outputs=[output_res],
|
| 61 |
+
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
demo.queue().launch(show_api=False, show_error=True)
|
| 65 |
+
|