Spaces:
Runtime error
Runtime error
Commit
Β·
3522486
1
Parent(s):
bf962dc
Updated app layout
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ def read_content(file_path: str) -> str:
|
|
| 17 |
return content
|
| 18 |
|
| 19 |
def predict(dict, prompt="", guidance_scale=7.5, steps=20, strength=1.0, scheduler="EulerDiscreteScheduler"):
|
|
|
|
| 20 |
scheduler_class_name = scheduler.split("-")[0]
|
| 21 |
|
| 22 |
add_kwargs = {}
|
|
@@ -33,11 +34,11 @@ def predict(dict, prompt="", guidance_scale=7.5, steps=20, strength=1.0, schedul
|
|
| 33 |
|
| 34 |
output = pipe(prompt = prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
|
| 35 |
|
| 36 |
-
return output.images[0], gr.update(visible=True)
|
| 37 |
|
| 38 |
|
| 39 |
css = '''
|
| 40 |
-
.container
|
| 41 |
#image_upload{min-height:400px}
|
| 42 |
#image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
|
| 43 |
#mask_radio .gr-form{background:transparent; border: none}
|
|
@@ -57,61 +58,55 @@ css = '''
|
|
| 57 |
transform: rotate(360deg);
|
| 58 |
}
|
| 59 |
}
|
| 60 |
-
#share-btn-container {
|
| 61 |
-
|
| 62 |
-
}
|
| 63 |
-
#share-btn {
|
| 64 |
-
|
| 65 |
-
}
|
| 66 |
-
#share-btn
|
| 67 |
-
|
| 68 |
-
}
|
| 69 |
-
#
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
}
|
| 73 |
-
#
|
| 74 |
-
display: none !important;
|
| 75 |
-
}
|
| 76 |
'''
|
| 77 |
|
| 78 |
-
image_blocks = gr.Blocks(css=css)
|
| 79 |
with image_blocks as demo:
|
| 80 |
gr.HTML(read_content("header.html"))
|
| 81 |
-
with gr.
|
| 82 |
-
with gr.Box():
|
| 83 |
-
with gr.Row():
|
| 84 |
with gr.Column():
|
| 85 |
image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload").style(height=400)
|
| 86 |
-
with gr.Row(elem_id="prompt-container"
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
btn = gr.Button("Inpaint!").style(
|
| 99 |
-
margin=False,
|
| 100 |
-
rounded=(False, True, True, False),
|
| 101 |
-
full_width=False,
|
| 102 |
-
)
|
| 103 |
with gr.Column():
|
| 104 |
image_out = gr.Image(label="Output", elem_id="output-img").style(height=400)
|
| 105 |
-
with gr.Group(elem_id="share-btn-container"):
|
| 106 |
-
community_icon = gr.HTML(community_icon_html
|
| 107 |
-
loading_icon = gr.HTML(loading_icon_html
|
| 108 |
-
share_button = gr.Button("Share to community", elem_id="share-btn",
|
| 109 |
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
| 115 |
examples=[
|
| 116 |
["./imgs/aaa (8).png"],
|
| 117 |
["./imgs/download (1).jpeg"],
|
|
@@ -127,14 +122,14 @@ with image_blocks as demo:
|
|
| 127 |
fn=predict,
|
| 128 |
inputs=[image],
|
| 129 |
cache_examples=False,
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
-
image_blocks.launch()
|
|
|
|
| 17 |
return content
|
| 18 |
|
| 19 |
def predict(dict, prompt="", guidance_scale=7.5, steps=20, strength=1.0, scheduler="EulerDiscreteScheduler"):
|
| 20 |
+
|
| 21 |
scheduler_class_name = scheduler.split("-")[0]
|
| 22 |
|
| 23 |
add_kwargs = {}
|
|
|
|
| 34 |
|
| 35 |
output = pipe(prompt = prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
|
| 36 |
|
| 37 |
+
return output.images[0], gr.update(visible=True)
|
| 38 |
|
| 39 |
|
| 40 |
css = '''
|
| 41 |
+
.gradio-container{max-width: 1100px !important}
|
| 42 |
#image_upload{min-height:400px}
|
| 43 |
#image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
|
| 44 |
#mask_radio .gr-form{background:transparent; border: none}
|
|
|
|
| 58 |
transform: rotate(360deg);
|
| 59 |
}
|
| 60 |
}
|
| 61 |
+
#share-btn-container {padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; max-width: 13rem; margin-left: auto;}
|
| 62 |
+
div#share-btn-container > div {flex-direction: row;background: black;align-items: center}
|
| 63 |
+
#share-btn-container:hover {background-color: #060606}
|
| 64 |
+
#share-btn {all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.5rem !important; padding-bottom: 0.5rem !important;right:0;}
|
| 65 |
+
#share-btn * {all: unset}
|
| 66 |
+
#share-btn-container div:nth-child(-n+2){width: auto !important;min-height: 0px !important;}
|
| 67 |
+
#share-btn-container .wrap {display: none !important}
|
| 68 |
+
#share-btn-container.hidden {display: none!important}
|
| 69 |
+
#prompt input{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
|
| 70 |
+
#run_button{position:absolute;margin-top: 11px;right: 0;margin-right: 0.8em;border-bottom-left-radius: 0px;
|
| 71 |
+
border-top-left-radius: 0px;}
|
| 72 |
+
#prompt-container{margin-top:-18px;}
|
| 73 |
+
#prompt-container .form{border-top-left-radius: 0;border-top-right-radius: 0}
|
| 74 |
+
#image_upload{border-bottom-left-radius: 0px;border-bottom-right-radius: 0px}
|
|
|
|
|
|
|
| 75 |
'''
|
| 76 |
|
| 77 |
+
image_blocks = gr.Blocks(css=css, elem_id="total-container")
|
| 78 |
with image_blocks as demo:
|
| 79 |
gr.HTML(read_content("header.html"))
|
| 80 |
+
with gr.Row():
|
|
|
|
|
|
|
| 81 |
with gr.Column():
|
| 82 |
image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload").style(height=400)
|
| 83 |
+
with gr.Row(elem_id="prompt-container", mobile_collapse=False, equal_height=True):
|
| 84 |
+
with gr.Row():
|
| 85 |
+
prompt = gr.Textbox(placeholder="Your prompt (what you want in place of what is erased)", show_label=False, elem_id="prompt")
|
| 86 |
+
btn = gr.Button("Inpaint!", elem_id="run_button")
|
| 87 |
+
|
| 88 |
+
with gr.Accordion(label="Advanced Settings", open=False):
|
| 89 |
+
with gr.Row(mobile_collapse=False, equal_height=True):
|
| 90 |
+
guidance_scale = gr.Number(value=7.5, minimum=1.0, maximum=20.0, step=0.1, label="guidance_scale")
|
| 91 |
+
steps = gr.Number(value=20, minimum=10, maximum=30, step=1, label="steps")
|
| 92 |
+
strength = gr.Number(value=0.99, minimum=0.0, maximum=0.99, step=0.01, label="strength")
|
| 93 |
+
|
| 94 |
+
with gr.Row(mobile_collapse=False, equal_height=True):
|
| 95 |
+
schedulers = ["DEISMultistepScheduler", "HeunDiscreteScheduler", "EulerDiscreteScheduler", "DPMSolverMultistepScheduler", "DPMSolverMultistepScheduler-Karras", "DPMSolverMultistepScheduler-Karras-SDE"]
|
| 96 |
+
scheduler = gr.Dropdown(label="Schedulers", choices=schedulers, value="EulerDiscreteScheduler")
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
with gr.Column():
|
| 99 |
image_out = gr.Image(label="Output", elem_id="output-img").style(height=400)
|
| 100 |
+
with gr.Group(elem_id="share-btn-container", visible=False) as share_btn_container:
|
| 101 |
+
community_icon = gr.HTML(community_icon_html)
|
| 102 |
+
loading_icon = gr.HTML(loading_icon_html)
|
| 103 |
+
share_button = gr.Button("Share to community", elem_id="share-btn",visible=True)
|
| 104 |
|
| 105 |
|
| 106 |
+
btn.click(fn=predict, inputs=[image, prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container])
|
| 107 |
+
share_button.click(None, [], [], _js=share_js)
|
| 108 |
|
| 109 |
+
gr.Examples(
|
| 110 |
examples=[
|
| 111 |
["./imgs/aaa (8).png"],
|
| 112 |
["./imgs/download (1).jpeg"],
|
|
|
|
| 122 |
fn=predict,
|
| 123 |
inputs=[image],
|
| 124 |
cache_examples=False,
|
| 125 |
+
)
|
| 126 |
+
gr.HTML(
|
| 127 |
+
"""
|
| 128 |
+
<div class="footer">
|
| 129 |
+
<p>Model by <a href="https://huggingface.co/diffusers" style="text-decoration: underline;" target="_blank">Diffusers</a> - Gradio Demo by π€ Hugging Face
|
| 130 |
+
</p>
|
| 131 |
+
</div>
|
| 132 |
+
"""
|
| 133 |
+
)
|
| 134 |
|
| 135 |
+
image_blocks.launch()
|