CoderLim commited on
Commit
33ac0ae
·
verified ·
1 Parent(s): 81e6133

feat: iframe src 支持传入 prompt

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py CHANGED
@@ -530,6 +530,55 @@ with gr.Blocks(css=CSS, title="Krea 2 Identity Edit") as demo:
530
  """
531
  )
532
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
533
  with gr.Row(equal_height=True):
534
  with gr.Column():
535
  source_image = gr.Image(label="Source image", type="pil", height=420)
 
530
  """
531
  )
532
 
533
+ gr.HTML(
534
+ """
535
+ <script>
536
+ (() => {
537
+ const getPromptFromUrl = () => {
538
+ const params = new URLSearchParams(window.location.search);
539
+ return params.get("prompt") || "";
540
+ };
541
+
542
+ const applyPrompt = () => {
543
+ const prompt = getPromptFromUrl();
544
+ if (!prompt) return;
545
+
546
+ const textarea = document.querySelector("textarea");
547
+ if (!textarea) return false;
548
+
549
+ if (textarea.value !== prompt) {
550
+ textarea.value = prompt;
551
+ textarea.dispatchEvent(new Event("input", { bubbles: true }));
552
+ textarea.dispatchEvent(new Event("change", { bubbles: true }));
553
+ }
554
+ return true;
555
+ };
556
+
557
+ const start = () => {
558
+ if (applyPrompt()) return;
559
+
560
+ const observer = new MutationObserver(() => {
561
+ if (applyPrompt()) observer.disconnect();
562
+ });
563
+
564
+ observer.observe(document.body, {
565
+ childList: true,
566
+ subtree: true
567
+ });
568
+
569
+ setTimeout(() => observer.disconnect(), 10000);
570
+ };
571
+
572
+ if (document.readyState === "loading") {
573
+ document.addEventListener("DOMContentLoaded", start);
574
+ } else {
575
+ start();
576
+ }
577
+ })();
578
+ </script>
579
+ """
580
+ )
581
+
582
  with gr.Row(equal_height=True):
583
  with gr.Column():
584
  source_image = gr.Image(label="Source image", type="pil", height=420)