div0-space commited on
Commit
f1c4fa9
·
verified ·
1 Parent(s): a89e2d5

Embed tester HTML via srcdoc iframe to sandbox JS scope

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -11,6 +11,7 @@ from pathlib import Path
11
  from typing import List, Tuple
12
 
13
  import gradio as gr
 
14
 
15
  BASE_DIR = Path(__file__).parent
16
  HTML_PATH = BASE_DIR / "api-tester.html"
@@ -41,8 +42,14 @@ def build_auth() -> List[Tuple[str, str]] | None:
41
 
42
 
43
  def build_demo(html: str, auth: List[Tuple[str, str]] | None) -> gr.Blocks:
 
 
 
 
 
 
44
  with gr.Blocks(title="LibraxisAI API Batch Tester", css="body{background:#0b0b0c;}") as demo:
45
- gr.HTML(html)
46
  port = int(os.getenv("PORT", os.getenv("GRADIO_PORT", "7860")))
47
  demo.launch(
48
  server_name="0.0.0.0",
 
11
  from typing import List, Tuple
12
 
13
  import gradio as gr
14
+ import html as py_html
15
 
16
  BASE_DIR = Path(__file__).parent
17
  HTML_PATH = BASE_DIR / "api-tester.html"
 
42
 
43
 
44
  def build_demo(html: str, auth: List[Tuple[str, str]] | None) -> gr.Blocks:
45
+ escaped = py_html.escape(html, quote=True)
46
+ iframe = (
47
+ "<iframe id='tester-frame' title='LibraxisAI Responses API Tester' "
48
+ "style=\"width:100%;height:90vh;border:none;background:#0b0b0c;\" "
49
+ f"srcdoc=\"{escaped}\"></iframe>"
50
+ )
51
  with gr.Blocks(title="LibraxisAI API Batch Tester", css="body{background:#0b0b0c;}") as demo:
52
+ gr.HTML(iframe)
53
  port = int(os.getenv("PORT", os.getenv("GRADIO_PORT", "7860")))
54
  demo.launch(
55
  server_name="0.0.0.0",