Update app.py
Browse files
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 |
-
#
|
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 =
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
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 |
|