srishtisrivastavaphd commited on
Commit
d998c04
·
verified ·
1 Parent(s): 8782dad

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +152 -17
index.html CHANGED
@@ -1,19 +1,154 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
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>Zero-Shot Topic Classifier</title>
7
+ <style>
8
+ :root {
9
+ --bg: #f6f7f9; --card: #ffffff; --ink: #1c2230; --muted: #5d6677;
10
+ --line: #dde1e8; --accent: #2f5bd3; --accent-ink: #ffffff; --bar: #2f5bd3;
11
+ --bar-bg: #e8ecf5; --warn: #9a5b00; --warn-bg: #fff4e0;
12
+ }
13
+ @media (prefers-color-scheme: dark) {
14
+ :root {
15
+ --bg: #12151c; --card: #1b2029; --ink: #e9ecf2; --muted: #a2aabb;
16
+ --line: #2d3442; --accent: #6f93ff; --accent-ink: #0d1220; --bar: #6f93ff;
17
+ --bar-bg: #262d3b; --warn: #ffc56b; --warn-bg: #2e2516;
18
+ }
19
+ }
20
+ * { box-sizing: border-box; }
21
+ body { margin: 0; background: var(--bg); color: var(--ink);
22
+ font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
23
+ main { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }
24
+ h1 { font-size: 1.5rem; margin: 0 0 4px; }
25
+ .sub { color: var(--muted); margin: 0 0 20px; }
26
+ .card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
27
+ label { display: block; font-weight: 600; margin: 0 0 6px; }
28
+ .hint { font-weight: 400; color: var(--muted); font-size: .9rem; }
29
+ textarea, input[type=text] { width: 100%; padding: 10px 12px; border: 1px solid var(--line);
30
+ border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; }
31
+ textarea { min-height: 140px; resize: vertical; }
32
+ .row { margin-bottom: 14px; }
33
+ .check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
34
+ button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
35
+ padding: 11px 22px; font: 600 1rem system-ui, sans-serif; cursor: pointer; }
36
+ button:disabled { opacity: .55; cursor: wait; }
37
+ #status { margin-top: 12px; color: var(--muted); font-size: .95rem; min-height: 1.5em; }
38
+ progress { width: 100%; height: 10px; margin-top: 8px; display: none; }
39
+ .warn { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 12px; font-size: .9rem; margin-top: 12px; display: none; }
40
+ .res { display: grid; grid-template-columns: minmax(110px, 34%) 1fr 64px; gap: 8px 12px; align-items: center; }
41
+ .res .name { overflow-wrap: anywhere; }
42
+ .res .top { font-weight: 700; }
43
+ .track { background: var(--bar-bg); border-radius: 6px; height: 14px; overflow: hidden; }
44
+ .fill { background: var(--bar); height: 100%; }
45
+ .pct { text-align: right; font-variant-numeric: tabular-nums; }
46
+ .record { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: .95rem; }
47
+ .record code { background: var(--bar-bg); padding: 2px 6px; border-radius: 4px; }
48
+ footer { color: var(--muted); font-size: .85rem; }
49
+ </style>
50
+ </head>
51
+ <body>
52
+ <main>
53
+ <h1>Zero-Shot Topic Classifier</h1>
54
+ <p class="sub">Semantic analysis: what is this text about? Model: facebook/bart-large-mnli, running free in your browser. No account or credits needed.</p>
55
+
56
+ <div class="card">
57
+ <div class="row">
58
+ <label for="text">Review text</label>
59
+ <textarea id="text" placeholder="Paste one customer review here..."></textarea>
60
+ </div>
61
+ <div class="row">
62
+ <label for="labels">Candidate labels <span class="hint">(4 to 6 topics, separated by commas)</span></label>
63
+ <input id="labels" type="text" placeholder="product quality, price, speed of service, staff friendliness, mobile app">
64
+ </div>
65
+ <div class="row">
66
+ <label class="check"><input id="multi" type="checkbox"> Allow multiple true labels <span class="hint">(leave unchecked for the assignment)</span></label>
67
+ </div>
68
+ <button id="run">Classify</button>
69
+ <progress id="prog" max="100" value="0"></progress>
70
+ <div id="status">The first run downloads the model (about 400 MB, one time only). Later runs take a few seconds.</div>
71
+ <div id="warn" class="warn"></div>
72
+ </div>
73
+
74
+ <div class="card" id="out" hidden>
75
+ <div class="res" id="bars"></div>
76
+ <div class="record" id="record"></div>
77
+ </div>
78
+
79
+ <footer>Runs on Transformers.js. Your text never leaves your computer. Use Chrome, Edge or Firefox on a laptop or desktop.</footer>
80
+ </main>
81
+
82
+ <script type="module">
83
+ import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.8.1";
84
+
85
+ const $ = (id) => document.getElementById(id);
86
+ const runBtn = $("run"), status = $("status"), prog = $("prog"), warn = $("warn");
87
+ let classifierPromise = null;
88
+
89
+ function loadModel() {
90
+ if (classifierPromise) return classifierPromise;
91
+ const files = {};
92
+ prog.style.display = "block";
93
+ classifierPromise = pipeline("zero-shot-classification", "Xenova/bart-large-mnli", {
94
+ dtype: "q8",
95
+ progress_callback: (p) => {
96
+ if (p.status === "progress" && p.total) {
97
+ files[p.file] = { loaded: p.loaded, total: p.total };
98
+ const all = Object.values(files);
99
+ const loaded = all.reduce((s, f) => s + f.loaded, 0);
100
+ const total = all.reduce((s, f) => s + f.total, 0);
101
+ prog.value = Math.round((loaded / total) * 100);
102
+ status.textContent = `Downloading model: ${Math.round(loaded / 1e6)} of ${Math.round(total / 1e6)} MB (one time only)...`;
103
+ } else if (p.status === "ready") {
104
+ status.textContent = "Model loaded. Classifying...";
105
+ }
106
+ },
107
+ }).then((c) => { prog.style.display = "none"; return c; })
108
+ .catch((e) => { classifierPromise = null; prog.style.display = "none"; throw e; });
109
+ return classifierPromise;
110
+ }
111
+
112
+ function showWarn(msg) { warn.textContent = msg; warn.style.display = msg ? "block" : "none"; }
113
+
114
+ function esc(s) {
115
+ return s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
116
+ }
117
+
118
+ runBtn.addEventListener("click", async () => {
119
+ const text = $("text").value.trim();
120
+ const labels = [...new Set($("labels").value.split(",").map((s) => s.trim()).filter(Boolean))];
121
+ showWarn("");
122
+ if (!text) { showWarn("Paste a review first."); return; }
123
+ if (labels.length < 2) { showWarn("Enter at least 2 labels, separated by commas."); return; }
124
+ if (labels.length > 6) showWarn("The assignment asks for 4 to 6 labels. You entered " + labels.length + ".");
125
+
126
+ runBtn.disabled = true;
127
+ try {
128
+ const classifier = await loadModel();
129
+ status.textContent = "Classifying...";
130
+ const t0 = performance.now();
131
+ const out = await classifier(text, labels, { multi_label: $("multi").checked });
132
+ const secs = ((performance.now() - t0) / 1000).toFixed(1);
133
+
134
+ $("bars").innerHTML = out.labels.map((lab, i) => {
135
+ const pct = (out.scores[i] * 100).toFixed(1);
136
+ return `<div class="name ${i === 0 ? "top" : ""}">${esc(lab)}</div>
137
+ <div class="track"><div class="fill" style="width:${pct}%"></div></div>
138
+ <div class="pct">${out.scores[i].toFixed(3)}</div>`;
139
+ }).join("");
140
+ $("record").innerHTML = `Record in your sheet: top label <code>${esc(out.labels[0])}</code>, score <code>${out.scores[0].toFixed(3)}</code>` +
141
+ ($("multi").checked ? " (multi-label mode: scores are independent and do not add to 1)" : " (scores add up to 1)");
142
+ $("out").hidden = false;
143
+ status.textContent = `Done in ${secs} s.`;
144
+ } catch (e) {
145
+ console.error(e);
146
+ status.textContent = "";
147
+ showWarn("Something went wrong: " + (e && e.message ? e.message : e) + ". Refresh the page and try again, or try another browser.");
148
+ } finally {
149
+ runBtn.disabled = false;
150
+ }
151
+ });
152
+ </script>
153
+ </body>
154
  </html>