openfree commited on
Commit
eaea494
·
verified ·
1 Parent(s): 18d8ce4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import urllib.parse
 
2
  import gradio as gr
3
 
4
  # -------------------------------------------------
@@ -247,7 +248,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
247
  '''
248
  html_items += '</div>'
249
 
250
- # ------------- React Controlled Input Hack -------------
251
  hack_js = """
252
  function updateReactValue(el,newVal){
253
  if(!el)return;
@@ -274,29 +275,29 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
274
  }
275
  """
276
 
277
- # 예제 클릭 시 자동 채우기
278
- apply_example_js = f"""
279
- <script>
280
- {hack_js}
281
- const examples={examples};
282
- function applyExample(i){{
283
- const ex=examples[i];
284
- const labelBox=document.querySelector("#label-input textarea,#label-input input");
285
- if(labelBox)updateReactValue(labelBox,ex[0]);
286
- const msgBox=document.querySelector("#message-input textarea,#message-input input");
287
- if(msgBox)updateReactValue(msgBox,ex[1]);
288
- setColorValue("color-input",convertToHexIfNeeded(ex[2]));
289
- setColorValue("label-color-input",convertToHexIfNeeded(ex[3]));
290
- const logoBox=document.querySelector("#logo-input textarea,#logo-input input");
291
- if(logoBox)updateReactValue(logoBox,ex[4]);
292
- setColorValue("logo-color-input",convertToHexIfNeeded(ex[5]));
293
- const styleSel=document.querySelector("#style-input select");
294
- if(styleSel){styleSel.value=ex[6];styleSel.dispatchEvent(new Event("change",{bubbles:true}));}
295
- const linkBox=document.querySelector("#link-input textarea,#link-input input");
296
- if(linkBox)updateReactValue(linkBox,ex[7]);
297
- }}
298
- </script>
299
- """
300
 
301
  gr.HTML(html_items + apply_example_js)
302
 
 
1
  import urllib.parse
2
+ import json
3
  import gradio as gr
4
 
5
  # -------------------------------------------------
 
248
  '''
249
  html_items += '</div>'
250
 
251
+ # ---------- React Controlled Input Hack (JS) ----------
252
  hack_js = """
253
  function updateReactValue(el,newVal){
254
  if(!el)return;
 
275
  }
276
  """
277
 
278
+ # ---------- 예제 클릭 시 자동 채우기 스크립트 ----------
279
+ apply_example_js = (
280
+ "<script>\n"
281
+ + hack_js + "\n"
282
+ + "const examples = " + json.dumps(examples) + ";\n"
283
+ + "function applyExample(i) {\n"
284
+ + " const ex = examples[i];\n"
285
+ + " const labelBox=document.querySelector(\"#label-input textarea,#label-input input\");\n"
286
+ + " if(labelBox) updateReactValue(labelBox,ex[0]);\n"
287
+ + " const msgBox=document.querySelector(\"#message-input textarea,#message-input input\");\n"
288
+ + " if(msgBox) updateReactValue(msgBox,ex[1]);\n"
289
+ + " setColorValue(\"color-input\",convertToHexIfNeeded(ex[2]));\n"
290
+ + " setColorValue(\"label-color-input\",convertToHexIfNeeded(ex[3]));\n"
291
+ + " const logoBox=document.querySelector(\"#logo-input textarea,#logo-input input\");\n"
292
+ + " if(logoBox) updateReactValue(logoBox,ex[4]);\n"
293
+ + " setColorValue(\"logo-color-input\",convertToHexIfNeeded(ex[5]));\n"
294
+ + " const styleSel=document.querySelector(\"#style-input select\");\n"
295
+ + " if(styleSel) { styleSel.value=ex[6]; styleSel.dispatchEvent(new Event(\"change\",{bubbles:true})); }\n"
296
+ + " const linkBox=document.querySelector(\"#link-input textarea,#link-input input\");\n"
297
+ + " if(linkBox) updateReactValue(linkBox,ex[7]);\n"
298
+ + "}\n"
299
+ + "</script>"
300
+ )
301
 
302
  gr.HTML(html_items + apply_example_js)
303