Spaces:
Running on Zero
Running on Zero
Update app_image_edit.py
Browse files- app_image_edit.py +25 -11
app_image_edit.py
CHANGED
|
@@ -22,7 +22,7 @@ from diffusers import QwenImageEditPlusPipeline, FlowMatchEulerDiscreteScheduler
|
|
| 22 |
from huggingface_hub import InferenceClient
|
| 23 |
|
| 24 |
|
| 25 |
-
from config_image_edit import TITLE, LOGO_HTML, CUSTOM_HEAD,
|
| 26 |
|
| 27 |
log = logging.getLogger(__name__)
|
| 28 |
|
|
@@ -243,13 +243,22 @@ def polish_prompt_hf(original_prompt, img_list):
|
|
| 243 |
return original_prompt
|
| 244 |
|
| 245 |
|
| 246 |
-
|
| 247 |
def encode_image(pil_image):
|
| 248 |
import io
|
| 249 |
buffered = io.BytesIO()
|
| 250 |
pil_image.save(buffered, format="PNG")
|
| 251 |
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
@spaces.GPU(duration=300)
|
| 254 |
def infer(
|
| 255 |
images,
|
|
@@ -323,10 +332,11 @@ def infer(
|
|
| 323 |
except Exception as exc:
|
| 324 |
raise gr.Error(f"Fehler beim Speichern des Bildes: {exc}")
|
| 325 |
|
| 326 |
-
|
| 327 |
-
|
|
|
|
| 328 |
|
| 329 |
-
return str(image_path), seed,
|
| 330 |
|
| 331 |
|
| 332 |
# ------------------
|
|
@@ -402,18 +412,19 @@ with gr.Blocks(title=TITLE) as demo:
|
|
| 402 |
|
| 403 |
rewrite_prompt = gr.Checkbox(label="✨ Prompt verbessern", value=True, elem_classes="einstellungen-rewrite-prompt", interactive=True)
|
| 404 |
|
| 405 |
-
|
|
|
|
| 406 |
|
| 407 |
with gr.Column(elem_classes="output-column", visible=False) as output_column_1:
|
| 408 |
# output_video = gr.Video(value=None, label="Ergebnis", show_label=False, elem_classes="result-video", visible=True, interactive=False)
|
| 409 |
with gr.Row(elem_classes="gradio-row", equal_height=True):
|
| 410 |
with gr.Column():
|
| 411 |
gr.Markdown("# **** Ergebnis", elem_classes="markdown-label")
|
| 412 |
-
result_image = gr.Image(label="Ergebnis", type="
|
| 413 |
|
| 414 |
with gr.Column():
|
| 415 |
gr.Markdown("# **** Verlauf", elem_classes="markdown-label")
|
| 416 |
-
result_history = gr.Gallery([], label="Ergebnis", show_label=False, buttons=["download", "fullscreen"], object_fit="cover", elem_classes="result-gallery", interactive=False, allow_preview=
|
| 417 |
|
| 418 |
# greet_btn.click(fn=greet, inputs=[], outputs=output, api_name="greet")
|
| 419 |
with gr.Tab(" Info", elem_classes="info-tab"):
|
|
@@ -438,11 +449,14 @@ with gr.Blocks(title=TITLE) as demo:
|
|
| 438 |
|
| 439 |
randomize_seed_checkbox.change(fn=lambda x: gr.update(interactive=(not x)), inputs=[randomize_seed_checkbox], outputs=[seed_input], show_progress=False)
|
| 440 |
guidance_scale_input.change(fn=lambda x: gr.update(interactive=(x > 2)), inputs=[guidance_scale_input], outputs=[negative_prompt_input], show_progress=False)
|
|
|
|
|
|
|
| 441 |
|
| 442 |
ui_inputs = [input_image_component, prompt, negative_prompt_input, steps_slider, guidance_scale_input, seed_input, randomize_seed_checkbox, rewrite_prompt, result_history]
|
| 443 |
-
generate_button.click(fn=lambda:
|
| 444 |
-
fn=
|
| 445 |
)
|
| 446 |
|
| 447 |
if __name__ == "__main__":
|
| 448 |
-
demo.launch(theme=THEME, head=CUSTOM_HEAD, css=CUSTOM_CSS, footer_links=["gradio", "settings"])
|
|
|
|
|
|
| 22 |
from huggingface_hub import InferenceClient
|
| 23 |
|
| 24 |
|
| 25 |
+
from config_image_edit import TITLE, LOGO_HTML, CUSTOM_HEAD, HEADLINE_MD, SUBHEADLINE_MD, THEME, DEFAULT_PROMPT, PROMPT_PLACEHOLDER, DEFAULT_PROMPT_NEGATIVE, DATA_IMAGE_WINK, DATA_IMAGE_HEART
|
| 26 |
|
| 27 |
log = logging.getLogger(__name__)
|
| 28 |
|
|
|
|
| 243 |
return original_prompt
|
| 244 |
|
| 245 |
|
|
|
|
| 246 |
def encode_image(pil_image):
|
| 247 |
import io
|
| 248 |
buffered = io.BytesIO()
|
| 249 |
pil_image.save(buffered, format="PNG")
|
| 250 |
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 251 |
|
| 252 |
+
|
| 253 |
+
def use_history_as_input(evt: gr.SelectData, history):
|
| 254 |
+
if history and evt.index < len(history):
|
| 255 |
+
im = history[evt.index][0]
|
| 256 |
+
image_path = f"image_cache/{history[evt.index][1]}"
|
| 257 |
+
im.save(image_path, format="PNG")
|
| 258 |
+
return image_path # gr.update(value=history[evt.index][0])
|
| 259 |
+
return # gr.update()
|
| 260 |
+
|
| 261 |
+
|
| 262 |
@spaces.GPU(duration=300)
|
| 263 |
def infer(
|
| 264 |
images,
|
|
|
|
| 332 |
except Exception as exc:
|
| 333 |
raise gr.Error(f"Fehler beim Speichern des Bildes: {exc}")
|
| 334 |
|
| 335 |
+
if gallery is None:
|
| 336 |
+
gallery = []
|
| 337 |
+
gallery.insert(0, (image, str(f"{timestamp}.png")))
|
| 338 |
|
| 339 |
+
return str(image_path), seed, gallery
|
| 340 |
|
| 341 |
|
| 342 |
# ------------------
|
|
|
|
| 412 |
|
| 413 |
rewrite_prompt = gr.Checkbox(label="✨ Prompt verbessern", value=True, elem_classes="einstellungen-rewrite-prompt", interactive=True)
|
| 414 |
|
| 415 |
+
game_button = gr.Button("Bearbeiten ✨", variant="primary", elem_classes="gradio-button run-button", elem_id="gameBtn", size="lg")
|
| 416 |
+
generate_button = gr.Button("Bearbeiten ✨", variant="primary", elem_classes="gradio-button run-button", elem_id="runBtn", size="lg")
|
| 417 |
|
| 418 |
with gr.Column(elem_classes="output-column", visible=False) as output_column_1:
|
| 419 |
# output_video = gr.Video(value=None, label="Ergebnis", show_label=False, elem_classes="result-video", visible=True, interactive=False)
|
| 420 |
with gr.Row(elem_classes="gradio-row", equal_height=True):
|
| 421 |
with gr.Column():
|
| 422 |
gr.Markdown("# **** Ergebnis", elem_classes="markdown-label")
|
| 423 |
+
result_image = gr.Image(label="Ergebnis", type="pil", show_label=False, buttons=["download", "fullscreen"], elem_classes="result-image", visible=True, interactive=False)
|
| 424 |
|
| 425 |
with gr.Column():
|
| 426 |
gr.Markdown("# **** Verlauf", elem_classes="markdown-label")
|
| 427 |
+
result_history = gr.Gallery([], label="Ergebnis", show_label=False, buttons=["download", "fullscreen"], object_fit="cover", elem_classes="result-gallery", interactive=False, allow_preview=False, type="pil")
|
| 428 |
|
| 429 |
# greet_btn.click(fn=greet, inputs=[], outputs=output, api_name="greet")
|
| 430 |
with gr.Tab(" Info", elem_classes="info-tab"):
|
|
|
|
| 449 |
|
| 450 |
randomize_seed_checkbox.change(fn=lambda x: gr.update(interactive=(not x)), inputs=[randomize_seed_checkbox], outputs=[seed_input], show_progress=False)
|
| 451 |
guidance_scale_input.change(fn=lambda x: gr.update(interactive=(x > 2)), inputs=[guidance_scale_input], outputs=[negative_prompt_input], show_progress=False)
|
| 452 |
+
|
| 453 |
+
result_history.select(fn=use_history_as_input, inputs=[result_history], outputs=[result_image], show_progress=False)
|
| 454 |
|
| 455 |
ui_inputs = [input_image_component, prompt, negative_prompt_input, steps_slider, guidance_scale_input, seed_input, randomize_seed_checkbox, rewrite_prompt, result_history]
|
| 456 |
+
generate_button.click(fn=lambda: gr.Column(visible=True), outputs=[output_column_1], show_progress=False, scroll_to_output=True).then(fn=infer, inputs=ui_inputs, outputs=[result_image, seed_input, result_history], show_progress_on=[result_image, result_history], scroll_to_output=True).then(
|
| 457 |
+
fn=None, outputs=generate_button, js="() => { document.getElementById('gameBtn').classList.remove('process-running'); }"
|
| 458 |
)
|
| 459 |
|
| 460 |
if __name__ == "__main__":
|
| 461 |
+
# demo.launch(theme=THEME, head=CUSTOM_HEAD, css=CUSTOM_CSS, footer_links=["gradio", "settings"])
|
| 462 |
+
demo.launch(theme=THEME, head=CUSTOM_HEAD, css_paths=["_res/_custom_image_edit.css", "_res/miniGameButton.css"], footer_links=["gradio", "settings"])
|