Traxic Claude Opus 5.5 commited on
Commit
fb38eeb
·
1 Parent(s): 4440265

Add static in-browser build (stlite) for free hosting

Browse files

index.html runs the Streamlit app in the browser via Pyodide, so it
can be served from any static host. In the browser build only the
offline model is offered, since API keys cannot be kept secret there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +9 -1
  2. index.html +49 -0
app.py CHANGED
@@ -4,6 +4,7 @@ from __future__ import annotations
4
  import html
5
  import json
6
  import re
 
7
  from pathlib import Path
8
 
9
  import streamlit as st
@@ -88,10 +89,17 @@ st.set_page_config(page_title="Pərdə · Safe AI for Azerbaijani data", page_ic
88
  with st.sidebar:
89
  st.header("Settings")
90
  sector = st.selectbox("Sector", list(SECTORS), help="Loads a sample text and a typical task.")
 
 
91
  provider = st.selectbox(
92
- "AI provider", list(PROVIDERS), index=list(PROVIDERS).index("mock"),
93
  help="Any OpenAI-compatible API. 'mock' runs offline. Keys come from environment variables.",
94
  )
 
 
 
 
 
95
  model = st.text_input("Model (optional)", value="", placeholder=PROVIDERS[provider]["model"])
96
  enabled = st.multiselect("Data types to protect", ALL_ENTITIES, default=list(SECTORS[sector]["entities"]))
97
  st.caption("Personal data is masked on this machine. Only tags like [PERSON_1] reach the AI provider.")
 
4
  import html
5
  import json
6
  import re
7
+ import sys
8
  from pathlib import Path
9
 
10
  import streamlit as st
 
89
  with st.sidebar:
90
  st.header("Settings")
91
  sector = st.selectbox("Sector", list(SECTORS), help="Loads a sample text and a typical task.")
92
+ in_browser = sys.platform == "emscripten" # static web build (stlite / Pyodide)
93
+ providers = ["mock"] if in_browser else list(PROVIDERS)
94
  provider = st.selectbox(
95
+ "AI provider", providers, index=providers.index("mock"),
96
  help="Any OpenAI-compatible API. 'mock' runs offline. Keys come from environment variables.",
97
  )
98
+ if in_browser:
99
+ st.info(
100
+ "Web demo: runs entirely in your browser with the offline model. "
101
+ "To use OpenAI, Grok, Gemini or Ollama, run the app locally (run.bat) or with Docker."
102
+ )
103
  model = st.text_input("Model (optional)", value="", placeholder=PROVIDERS[provider]["model"])
104
  enabled = st.multiselect("Data types to protect", ALL_ENTITIES, default=list(SECTORS[sector]["entities"]))
105
  st.caption("Personal data is masked on this machine. Only tags like [PERSON_1] reach the AI provider.")
index.html ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Pərdə · Safe AI for Azerbaijani data</title>
7
+ <meta name="description" content="Masks Azerbaijani personal data before it reaches an AI model. Runs fully in your browser." />
8
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@stlite/browser@1.9.2/build/stlite.css" />
9
+ <style>
10
+ body { margin: 0; background: #0e1117; color: #fafafa; font-family: system-ui, sans-serif; }
11
+ #loading { padding: 48px 16px; text-align: center; }
12
+ #loading small { color: #9aa0a6; }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <div id="root">
17
+ <div id="loading">
18
+ <h2>🛡️ Pərdə</h2>
19
+ <p>Loading Python in your browser (about 10–20 seconds on first visit)…</p>
20
+ <small>Everything runs on your device. No personal data is uploaded.</small>
21
+ </div>
22
+ </div>
23
+ <script type="module">
24
+ import { mount } from "https://cdn.jsdelivr.net/npm/@stlite/browser@1.9.2/build/stlite.js";
25
+ const files = [
26
+ "app.py",
27
+ "perde/__init__.py",
28
+ "perde/names.py",
29
+ "perde/recognizers.py",
30
+ "perde/shield.py",
31
+ "perde/gateway.py",
32
+ "perde/lexicon.txt",
33
+ "eval/results.json",
34
+ ];
35
+ mount(
36
+ {
37
+ entrypoint: "app.py",
38
+ requirements: [],
39
+ files: Object.fromEntries(files.map((f) => [f, { url: "./" + f }])),
40
+ streamlitConfig: {
41
+ "theme.primaryColor": "#e63946",
42
+ "client.toolbarMode": "viewer",
43
+ },
44
+ },
45
+ document.getElementById("root"),
46
+ );
47
+ </script>
48
+ </body>
49
+ </html>