gsarti commited on
Commit
a473567
1 Parent(s): 402952a
src/README.md CHANGED
@@ -115,6 +115,7 @@ Highlights will disappear if the highlighted text is edited. Modals will appear
115
  show_legend_label=True,
116
  show_remove_tags_button=True,
117
  show_copy_button=False,
 
118
  )
119
 
120
  # Functions
@@ -144,11 +145,6 @@ Highlights will disappear if the highlighted text is edited. Modals will appear
144
  inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
145
  outputs=None,
146
  )
147
- high.change(
148
- fn=show_info,
149
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Change")],
150
- outputs=None,
151
- )
152
 
153
  if __name__ == "__main__":
154
  demo.launch()
 
115
  show_legend_label=True,
116
  show_remove_tags_button=True,
117
  show_copy_button=False,
118
+ color_map={"Error A": "blue", "Error B": "red", "Error C": "green"},
119
  )
120
 
121
  # Functions
 
145
  inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
146
  outputs=None,
147
  )
 
 
 
 
 
148
 
149
  if __name__ == "__main__":
150
  demo.launch()
src/backend/gradio_highlightedtextbox/templates/component/index.js CHANGED
@@ -364,24 +364,24 @@ function at(l, e = {}) {
364
  function k(T, S = {}) {
365
  r = T;
366
  const y = a = {};
367
- return l == null || S.hard || L.stiffness >= 1 && L.damping >= 1 ? (m = !0, s = st(), _ = T, t.set(l = r), Promise.resolve()) : (S.soft && (c = 1 / ((S.soft === !0 ? 0.5 : +S.soft) * 60), u = 0), f || (s = st(), m = !1, f = Bl((d) => {
368
  if (m)
369
  return m = !1, f = null, !1;
370
  u = Math.min(u + c, 1);
371
  const C = {
372
  inv_mass: u,
373
- opts: L,
374
  settled: !0,
375
  dt: (d - s) * 60 / 1e3
376
- }, j = Ye(C, _, l, r);
377
- return s = d, _ = l, t.set(l = j), C.settled && (f = null), !C.settled;
378
  })), new Promise((d) => {
379
  f.promise.then(() => {
380
  y === a && d();
381
  });
382
  }));
383
  }
384
- const L = {
385
  set: k,
386
  update: (T, S) => k(T(r, l), S),
387
  subscribe: t.subscribe,
@@ -389,7 +389,7 @@ function at(l, e = {}) {
389
  damping: i,
390
  precision: o
391
  };
392
- return L;
393
  }
394
  const {
395
  SvelteComponent: Zl,
@@ -1404,18 +1404,19 @@ function ai(l) {
1404
  }
1405
  function ri(l, e, t) {
1406
  const n = typeof document < "u";
1407
- let { value: i = [] } = e, { value_is_output: o = !1 } = e, { label: s } = e, { legend_label: f } = e, { info: a = void 0 } = e, { show_label: _ = !0 } = e, { show_legend: r = !1 } = e, { show_legend_label: u = !1 } = e, { container: c = !0 } = e, { color_map: m = {} } = e, { show_copy_button: k = !1 } = e, { show_remove_tags_button: L = !1 } = e, { disabled: T } = e, S, y = "", d = "", C, j = !m || Object.keys(m).length === 0 ? {} : m, h = {}, Z = !1, J = "";
1408
  function E() {
1409
- for (let g in j)
1410
- i.map(([M, F]) => F).includes(g) || delete j[g];
 
1411
  if (i.length > 0) {
1412
  for (let [g, M] of i)
1413
- if (M !== null && !(M in j)) {
1414
- let F = Xn(Object.keys(j).length);
1415
- j[M] = F;
1416
  }
1417
  }
1418
- t(13, h = Yn(j, n, C));
1419
  }
1420
  function O(g) {
1421
  i.length > 0 && g && (t(11, y = i.map(([M, F]) => M).join("")), t(12, d = i.map(([M, F]) => F !== null ? `<mark class="hl ${F}" style="background-color:${h[F].secondary}">${M}</mark>` : M).join("")), t(15, J = i.map(([M, F]) => F !== null ? `<${F}>${M}</${F}>` : M).join("")));
@@ -1504,7 +1505,7 @@ function ri(l, e, t) {
1504
  y = this.textContent, d = this.innerHTML, t(11, y), t(12, d);
1505
  }
1506
  return l.$$set = (g) => {
1507
- "value" in g && t(18, i = g.value), "value_is_output" in g && t(19, o = g.value_is_output), "label" in g && t(0, s = g.label), "legend_label" in g && t(1, f = g.legend_label), "info" in g && t(2, a = g.info), "show_label" in g && t(3, _ = g.show_label), "show_legend" in g && t(4, r = g.show_legend), "show_legend_label" in g && t(5, u = g.show_legend_label), "container" in g && t(6, c = g.container), "color_map" in g && t(20, m = g.color_map), "show_copy_button" in g && t(7, k = g.show_copy_button), "show_remove_tags_button" in g && t(8, L = g.show_remove_tags_button), "disabled" in g && t(9, T = g.disabled);
1508
  }, E(), O(!0), [
1509
  s,
1510
  f,
@@ -1514,7 +1515,7 @@ function ri(l, e, t) {
1514
  u,
1515
  c,
1516
  k,
1517
- L,
1518
  T,
1519
  S,
1520
  y,
@@ -1807,8 +1808,8 @@ function Si(l) {
1807
  };
1808
  }
1809
  function Ti(l, e, t) {
1810
- let { $$slots: n = {}, $$scope: i } = e, { height: o = void 0 } = e, { width: s = void 0 } = e, { elem_id: f = "" } = e, { elem_classes: a = [] } = e, { variant: _ = "solid" } = e, { border_mode: r = "base" } = e, { padding: u = !0 } = e, { type: c = "normal" } = e, { test_id: m = void 0 } = e, { explicit_call: k = !1 } = e, { container: L = !0 } = e, { visible: T = !0 } = e, { allow_overflow: S = !0 } = e, { scale: y = null } = e, { min_width: d = 0 } = e, C = c === "fieldset" ? "fieldset" : "div";
1811
- const j = (h) => {
1812
  if (h !== void 0) {
1813
  if (typeof h == "number")
1814
  return h + "px";
@@ -1817,7 +1818,7 @@ function Ti(l, e, t) {
1817
  }
1818
  };
1819
  return l.$$set = (h) => {
1820
- "height" in h && t(0, o = h.height), "width" in h && t(1, s = h.width), "elem_id" in h && t(2, f = h.elem_id), "elem_classes" in h && t(3, a = h.elem_classes), "variant" in h && t(4, _ = h.variant), "border_mode" in h && t(5, r = h.border_mode), "padding" in h && t(6, u = h.padding), "type" in h && t(16, c = h.type), "test_id" in h && t(7, m = h.test_id), "explicit_call" in h && t(8, k = h.explicit_call), "container" in h && t(9, L = h.container), "visible" in h && t(10, T = h.visible), "allow_overflow" in h && t(11, S = h.allow_overflow), "scale" in h && t(12, y = h.scale), "min_width" in h && t(13, d = h.min_width), "$$scope" in h && t(17, i = h.$$scope);
1821
  }, [
1822
  o,
1823
  s,
@@ -1828,13 +1829,13 @@ function Ti(l, e, t) {
1828
  u,
1829
  m,
1830
  k,
1831
- L,
1832
  T,
1833
  S,
1834
  y,
1835
  d,
1836
  C,
1837
- j,
1838
  c,
1839
  i,
1840
  n
@@ -2073,7 +2074,7 @@ function xi(l) {
2073
  /*timer*/
2074
  l[5] && Wt(l)
2075
  );
2076
- const L = [oo, io], T = [];
2077
  function S(d, C) {
2078
  return (
2079
  /*last_progress_level*/
@@ -2083,7 +2084,7 @@ function xi(l) {
2083
  )
2084
  );
2085
  }
2086
- ~(o = S(l)) && (s = T[o] = L[o](l));
2087
  let y = !/*timer*/
2088
  l[5] && Kt(l);
2089
  return {
@@ -2121,10 +2122,10 @@ function xi(l) {
2121
  /*variant*/
2122
  d[8] === "default"
2123
  );
2124
- let j = o;
2125
- o = S(d), o === j ? ~o && T[o].p(d, C) : (s && (vl(), Se(T[j], 1, 1, () => {
2126
- T[j] = null;
2127
- }), bl()), ~o ? (s = T[o], s ? s.p(d, C) : (s = T[o] = L[o](d), s.c()), qe(s, 1), s.m(f.parentNode, f)) : s = null), /*timer*/
2128
  d[5] ? y && (y.d(1), y = null) : y ? y.p(d, C) : (y = Kt(d), y.c(), y.m(a.parentNode, a));
2129
  },
2130
  i(d) {
@@ -2780,7 +2781,7 @@ async function _o(l, e = !0) {
2780
  }
2781
  }
2782
  function ao(l, e, t) {
2783
- let n, { $$slots: i = {}, $$scope: o } = e, { i18n: s } = e, { eta: f = null } = e, { queue_position: a } = e, { queue_size: _ } = e, { status: r } = e, { scroll_to_output: u = !1 } = e, { timer: c = !0 } = e, { show_progress: m = "full" } = e, { message: k = null } = e, { progress: L = null } = e, { variant: T = "default" } = e, { loading_text: S = "Loading..." } = e, { absolute: y = !0 } = e, { translucent: d = !1 } = e, { border: C = !1 } = e, { autoscroll: j } = e, h, Z = !1, J = 0, E = 0, O = null, R = null, ae = 0, A = null, K, D = null, me = !0;
2784
  const Le = () => {
2785
  t(0, f = t(26, O = t(19, he = null))), t(24, J = performance.now()), t(25, E = 0), Z = !0, ge();
2786
  };
@@ -2798,7 +2799,7 @@ function ao(l, e, t) {
2798
  let he = null;
2799
  function Oe(w) {
2800
  Rt[w ? "unshift" : "push"](() => {
2801
- D = w, t(16, D), t(7, L), t(14, A), t(15, K);
2802
  });
2803
  }
2804
  function Ae(w) {
@@ -2807,20 +2808,20 @@ function ao(l, e, t) {
2807
  });
2808
  }
2809
  return l.$$set = (w) => {
2810
- "i18n" in w && t(1, s = w.i18n), "eta" in w && t(0, f = w.eta), "queue_position" in w && t(2, a = w.queue_position), "queue_size" in w && t(3, _ = w.queue_size), "status" in w && t(4, r = w.status), "scroll_to_output" in w && t(21, u = w.scroll_to_output), "timer" in w && t(5, c = w.timer), "show_progress" in w && t(6, m = w.show_progress), "message" in w && t(22, k = w.message), "progress" in w && t(7, L = w.progress), "variant" in w && t(8, T = w.variant), "loading_text" in w && t(9, S = w.loading_text), "absolute" in w && t(10, y = w.absolute), "translucent" in w && t(11, d = w.translucent), "border" in w && t(12, C = w.border), "autoscroll" in w && t(23, j = w.autoscroll), "$$scope" in w && t(28, o = w.$$scope);
2811
  }, l.$$.update = () => {
2812
  l.$$.dirty[0] & /*eta, old_eta, timer_start, eta_from_start*/
2813
  218103809 && (f === null && t(0, f = O), f != null && O !== f && (t(27, R = (performance.now() - J) / 1e3 + f), t(19, he = R.toFixed(1)), t(26, O = f))), l.$$.dirty[0] & /*eta_from_start, timer_diff*/
2814
  167772160 && t(17, ae = R === null || R <= 0 || !E ? null : Math.min(E / R, 1)), l.$$.dirty[0] & /*progress*/
2815
- 128 && L != null && t(18, me = !1), l.$$.dirty[0] & /*progress, progress_level, progress_bar, last_progress_level*/
2816
- 114816 && (L != null ? t(14, A = L.map((w) => {
2817
  if (w.index != null && w.length != null)
2818
  return w.index / w.length;
2819
  if (w.progress != null)
2820
  return w.progress;
2821
  })) : t(14, A = null), A ? (t(15, K = A[A.length - 1]), D && (K === 0 ? t(16, D.style.transition = "0", D) : t(16, D.style.transition = "150ms", D))) : t(15, K = void 0)), l.$$.dirty[0] & /*status*/
2822
  16 && (r === "pending" ? Le() : b()), l.$$.dirty[0] & /*el, scroll_to_output, status, autoscroll*/
2823
- 10493968 && h && u && (r === "pending" || r === "complete") && _o(h, j), l.$$.dirty[0] & /*status, message*/
2824
  4194320, l.$$.dirty[0] & /*timer_diff*/
2825
  33554432 && t(20, n = E.toFixed(1));
2826
  }, [
@@ -2831,7 +2832,7 @@ function ao(l, e, t) {
2831
  r,
2832
  c,
2833
  m,
2834
- L,
2835
  T,
2836
  S,
2837
  y,
@@ -2847,7 +2848,7 @@ function ao(l, e, t) {
2847
  n,
2848
  u,
2849
  k,
2850
- j,
2851
  J,
2852
  E,
2853
  O,
@@ -3178,19 +3179,19 @@ function qo(l) {
3178
  };
3179
  }
3180
  function So(l, e, t) {
3181
- let { gradio: n } = e, { label: i = "Highlighted Textbox" } = e, { legend_label: o = "Highlights:" } = e, { info: s = void 0 } = e, { elem_id: f = "" } = e, { elem_classes: a = [] } = e, { visible: _ = !0 } = e, { value: r } = e, { show_label: u } = e, { show_legend: c } = e, { show_legend_label: m } = e, { color_map: k = {} } = e, { container: L = !0 } = e, { scale: T = null } = e, { min_width: S = void 0 } = e, { show_copy_button: y = !1 } = e, { show_remove_tags_button: d = !1 } = e, { loading_status: C = void 0 } = e, { value_is_output: j = !1 } = e, { combine_adjacent: h = !1 } = e, { interactive: Z = !0 } = e;
3182
  const J = !1, E = !0;
3183
  function O(b) {
3184
  r = b, t(0, r), t(20, h);
3185
  }
3186
  function R(b) {
3187
- j = b, t(2, j);
3188
  }
3189
  const ae = () => n.dispatch("change"), A = () => n.dispatch("input"), K = () => n.dispatch("submit"), D = () => n.dispatch("blur"), me = (b) => n.dispatch("select", b.detail), Le = () => n.dispatch("focus"), ge = function() {
3190
  console.log("test"), n.dispatch("clear");
3191
  };
3192
  return l.$$set = (b) => {
3193
- "gradio" in b && t(3, n = b.gradio), "label" in b && t(4, i = b.label), "legend_label" in b && t(5, o = b.legend_label), "info" in b && t(6, s = b.info), "elem_id" in b && t(7, f = b.elem_id), "elem_classes" in b && t(8, a = b.elem_classes), "visible" in b && t(9, _ = b.visible), "value" in b && t(0, r = b.value), "show_label" in b && t(10, u = b.show_label), "show_legend" in b && t(11, c = b.show_legend), "show_legend_label" in b && t(12, m = b.show_legend_label), "color_map" in b && t(1, k = b.color_map), "container" in b && t(13, L = b.container), "scale" in b && t(14, T = b.scale), "min_width" in b && t(15, S = b.min_width), "show_copy_button" in b && t(16, y = b.show_copy_button), "show_remove_tags_button" in b && t(17, d = b.show_remove_tags_button), "loading_status" in b && t(18, C = b.loading_status), "value_is_output" in b && t(2, j = b.value_is_output), "combine_adjacent" in b && t(20, h = b.combine_adjacent), "interactive" in b && t(19, Z = b.interactive);
3194
  }, l.$$.update = () => {
3195
  l.$$.dirty[0] & /*color_map*/
3196
  2 && !k && Object.keys(k).length && t(1, k), l.$$.dirty[0] & /*value, combine_adjacent*/
@@ -3198,7 +3199,7 @@ function So(l, e, t) {
3198
  }, [
3199
  r,
3200
  k,
3201
- j,
3202
  n,
3203
  i,
3204
  o,
@@ -3209,7 +3210,7 @@ function So(l, e, t) {
3209
  u,
3210
  c,
3211
  m,
3212
- L,
3213
  T,
3214
  S,
3215
  y,
 
364
  function k(T, S = {}) {
365
  r = T;
366
  const y = a = {};
367
+ return l == null || S.hard || j.stiffness >= 1 && j.damping >= 1 ? (m = !0, s = st(), _ = T, t.set(l = r), Promise.resolve()) : (S.soft && (c = 1 / ((S.soft === !0 ? 0.5 : +S.soft) * 60), u = 0), f || (s = st(), m = !1, f = Bl((d) => {
368
  if (m)
369
  return m = !1, f = null, !1;
370
  u = Math.min(u + c, 1);
371
  const C = {
372
  inv_mass: u,
373
+ opts: j,
374
  settled: !0,
375
  dt: (d - s) * 60 / 1e3
376
+ }, L = Ye(C, _, l, r);
377
+ return s = d, _ = l, t.set(l = L), C.settled && (f = null), !C.settled;
378
  })), new Promise((d) => {
379
  f.promise.then(() => {
380
  y === a && d();
381
  });
382
  }));
383
  }
384
+ const j = {
385
  set: k,
386
  update: (T, S) => k(T(r, l), S),
387
  subscribe: t.subscribe,
 
389
  damping: i,
390
  precision: o
391
  };
392
+ return j;
393
  }
394
  const {
395
  SvelteComponent: Zl,
 
1404
  }
1405
  function ri(l, e, t) {
1406
  const n = typeof document < "u";
1407
+ let { value: i = [] } = e, { value_is_output: o = !1 } = e, { label: s } = e, { legend_label: f } = e, { info: a = void 0 } = e, { show_label: _ = !0 } = e, { show_legend: r = !1 } = e, { show_legend_label: u = !1 } = e, { container: c = !0 } = e, { color_map: m = {} } = e, { show_copy_button: k = !1 } = e, { show_remove_tags_button: j = !1 } = e, { disabled: T } = e, S, y = "", d = "", C, L, h = {}, Z = !1, J = "";
1408
  function E() {
1409
+ L = !m || Object.keys(m).length === 0 ? {} : m;
1410
+ for (let g in L)
1411
+ i.map(([M, F]) => F).includes(g) || delete L[g];
1412
  if (i.length > 0) {
1413
  for (let [g, M] of i)
1414
+ if (M !== null && !(M in L)) {
1415
+ let F = Xn(Object.keys(L).length);
1416
+ L[M] = F;
1417
  }
1418
  }
1419
+ t(13, h = Yn(L, n, C));
1420
  }
1421
  function O(g) {
1422
  i.length > 0 && g && (t(11, y = i.map(([M, F]) => M).join("")), t(12, d = i.map(([M, F]) => F !== null ? `<mark class="hl ${F}" style="background-color:${h[F].secondary}">${M}</mark>` : M).join("")), t(15, J = i.map(([M, F]) => F !== null ? `<${F}>${M}</${F}>` : M).join("")));
 
1505
  y = this.textContent, d = this.innerHTML, t(11, y), t(12, d);
1506
  }
1507
  return l.$$set = (g) => {
1508
+ "value" in g && t(18, i = g.value), "value_is_output" in g && t(19, o = g.value_is_output), "label" in g && t(0, s = g.label), "legend_label" in g && t(1, f = g.legend_label), "info" in g && t(2, a = g.info), "show_label" in g && t(3, _ = g.show_label), "show_legend" in g && t(4, r = g.show_legend), "show_legend_label" in g && t(5, u = g.show_legend_label), "container" in g && t(6, c = g.container), "color_map" in g && t(20, m = g.color_map), "show_copy_button" in g && t(7, k = g.show_copy_button), "show_remove_tags_button" in g && t(8, j = g.show_remove_tags_button), "disabled" in g && t(9, T = g.disabled);
1509
  }, E(), O(!0), [
1510
  s,
1511
  f,
 
1515
  u,
1516
  c,
1517
  k,
1518
+ j,
1519
  T,
1520
  S,
1521
  y,
 
1808
  };
1809
  }
1810
  function Ti(l, e, t) {
1811
+ let { $$slots: n = {}, $$scope: i } = e, { height: o = void 0 } = e, { width: s = void 0 } = e, { elem_id: f = "" } = e, { elem_classes: a = [] } = e, { variant: _ = "solid" } = e, { border_mode: r = "base" } = e, { padding: u = !0 } = e, { type: c = "normal" } = e, { test_id: m = void 0 } = e, { explicit_call: k = !1 } = e, { container: j = !0 } = e, { visible: T = !0 } = e, { allow_overflow: S = !0 } = e, { scale: y = null } = e, { min_width: d = 0 } = e, C = c === "fieldset" ? "fieldset" : "div";
1812
+ const L = (h) => {
1813
  if (h !== void 0) {
1814
  if (typeof h == "number")
1815
  return h + "px";
 
1818
  }
1819
  };
1820
  return l.$$set = (h) => {
1821
+ "height" in h && t(0, o = h.height), "width" in h && t(1, s = h.width), "elem_id" in h && t(2, f = h.elem_id), "elem_classes" in h && t(3, a = h.elem_classes), "variant" in h && t(4, _ = h.variant), "border_mode" in h && t(5, r = h.border_mode), "padding" in h && t(6, u = h.padding), "type" in h && t(16, c = h.type), "test_id" in h && t(7, m = h.test_id), "explicit_call" in h && t(8, k = h.explicit_call), "container" in h && t(9, j = h.container), "visible" in h && t(10, T = h.visible), "allow_overflow" in h && t(11, S = h.allow_overflow), "scale" in h && t(12, y = h.scale), "min_width" in h && t(13, d = h.min_width), "$$scope" in h && t(17, i = h.$$scope);
1822
  }, [
1823
  o,
1824
  s,
 
1829
  u,
1830
  m,
1831
  k,
1832
+ j,
1833
  T,
1834
  S,
1835
  y,
1836
  d,
1837
  C,
1838
+ L,
1839
  c,
1840
  i,
1841
  n
 
2074
  /*timer*/
2075
  l[5] && Wt(l)
2076
  );
2077
+ const j = [oo, io], T = [];
2078
  function S(d, C) {
2079
  return (
2080
  /*last_progress_level*/
 
2084
  )
2085
  );
2086
  }
2087
+ ~(o = S(l)) && (s = T[o] = j[o](l));
2088
  let y = !/*timer*/
2089
  l[5] && Kt(l);
2090
  return {
 
2122
  /*variant*/
2123
  d[8] === "default"
2124
  );
2125
+ let L = o;
2126
+ o = S(d), o === L ? ~o && T[o].p(d, C) : (s && (vl(), Se(T[L], 1, 1, () => {
2127
+ T[L] = null;
2128
+ }), bl()), ~o ? (s = T[o], s ? s.p(d, C) : (s = T[o] = j[o](d), s.c()), qe(s, 1), s.m(f.parentNode, f)) : s = null), /*timer*/
2129
  d[5] ? y && (y.d(1), y = null) : y ? y.p(d, C) : (y = Kt(d), y.c(), y.m(a.parentNode, a));
2130
  },
2131
  i(d) {
 
2781
  }
2782
  }
2783
  function ao(l, e, t) {
2784
+ let n, { $$slots: i = {}, $$scope: o } = e, { i18n: s } = e, { eta: f = null } = e, { queue_position: a } = e, { queue_size: _ } = e, { status: r } = e, { scroll_to_output: u = !1 } = e, { timer: c = !0 } = e, { show_progress: m = "full" } = e, { message: k = null } = e, { progress: j = null } = e, { variant: T = "default" } = e, { loading_text: S = "Loading..." } = e, { absolute: y = !0 } = e, { translucent: d = !1 } = e, { border: C = !1 } = e, { autoscroll: L } = e, h, Z = !1, J = 0, E = 0, O = null, R = null, ae = 0, A = null, K, D = null, me = !0;
2785
  const Le = () => {
2786
  t(0, f = t(26, O = t(19, he = null))), t(24, J = performance.now()), t(25, E = 0), Z = !0, ge();
2787
  };
 
2799
  let he = null;
2800
  function Oe(w) {
2801
  Rt[w ? "unshift" : "push"](() => {
2802
+ D = w, t(16, D), t(7, j), t(14, A), t(15, K);
2803
  });
2804
  }
2805
  function Ae(w) {
 
2808
  });
2809
  }
2810
  return l.$$set = (w) => {
2811
+ "i18n" in w && t(1, s = w.i18n), "eta" in w && t(0, f = w.eta), "queue_position" in w && t(2, a = w.queue_position), "queue_size" in w && t(3, _ = w.queue_size), "status" in w && t(4, r = w.status), "scroll_to_output" in w && t(21, u = w.scroll_to_output), "timer" in w && t(5, c = w.timer), "show_progress" in w && t(6, m = w.show_progress), "message" in w && t(22, k = w.message), "progress" in w && t(7, j = w.progress), "variant" in w && t(8, T = w.variant), "loading_text" in w && t(9, S = w.loading_text), "absolute" in w && t(10, y = w.absolute), "translucent" in w && t(11, d = w.translucent), "border" in w && t(12, C = w.border), "autoscroll" in w && t(23, L = w.autoscroll), "$$scope" in w && t(28, o = w.$$scope);
2812
  }, l.$$.update = () => {
2813
  l.$$.dirty[0] & /*eta, old_eta, timer_start, eta_from_start*/
2814
  218103809 && (f === null && t(0, f = O), f != null && O !== f && (t(27, R = (performance.now() - J) / 1e3 + f), t(19, he = R.toFixed(1)), t(26, O = f))), l.$$.dirty[0] & /*eta_from_start, timer_diff*/
2815
  167772160 && t(17, ae = R === null || R <= 0 || !E ? null : Math.min(E / R, 1)), l.$$.dirty[0] & /*progress*/
2816
+ 128 && j != null && t(18, me = !1), l.$$.dirty[0] & /*progress, progress_level, progress_bar, last_progress_level*/
2817
+ 114816 && (j != null ? t(14, A = j.map((w) => {
2818
  if (w.index != null && w.length != null)
2819
  return w.index / w.length;
2820
  if (w.progress != null)
2821
  return w.progress;
2822
  })) : t(14, A = null), A ? (t(15, K = A[A.length - 1]), D && (K === 0 ? t(16, D.style.transition = "0", D) : t(16, D.style.transition = "150ms", D))) : t(15, K = void 0)), l.$$.dirty[0] & /*status*/
2823
  16 && (r === "pending" ? Le() : b()), l.$$.dirty[0] & /*el, scroll_to_output, status, autoscroll*/
2824
+ 10493968 && h && u && (r === "pending" || r === "complete") && _o(h, L), l.$$.dirty[0] & /*status, message*/
2825
  4194320, l.$$.dirty[0] & /*timer_diff*/
2826
  33554432 && t(20, n = E.toFixed(1));
2827
  }, [
 
2832
  r,
2833
  c,
2834
  m,
2835
+ j,
2836
  T,
2837
  S,
2838
  y,
 
2848
  n,
2849
  u,
2850
  k,
2851
+ L,
2852
  J,
2853
  E,
2854
  O,
 
3179
  };
3180
  }
3181
  function So(l, e, t) {
3182
+ let { gradio: n } = e, { label: i = "Highlighted Textbox" } = e, { legend_label: o = "Highlights:" } = e, { info: s = void 0 } = e, { elem_id: f = "" } = e, { elem_classes: a = [] } = e, { visible: _ = !0 } = e, { value: r } = e, { show_label: u } = e, { show_legend: c } = e, { show_legend_label: m } = e, { color_map: k = {} } = e, { container: j = !0 } = e, { scale: T = null } = e, { min_width: S = void 0 } = e, { show_copy_button: y = !1 } = e, { show_remove_tags_button: d = !1 } = e, { loading_status: C = void 0 } = e, { value_is_output: L = !1 } = e, { combine_adjacent: h = !1 } = e, { interactive: Z = !0 } = e;
3183
  const J = !1, E = !0;
3184
  function O(b) {
3185
  r = b, t(0, r), t(20, h);
3186
  }
3187
  function R(b) {
3188
+ L = b, t(2, L);
3189
  }
3190
  const ae = () => n.dispatch("change"), A = () => n.dispatch("input"), K = () => n.dispatch("submit"), D = () => n.dispatch("blur"), me = (b) => n.dispatch("select", b.detail), Le = () => n.dispatch("focus"), ge = function() {
3191
  console.log("test"), n.dispatch("clear");
3192
  };
3193
  return l.$$set = (b) => {
3194
+ "gradio" in b && t(3, n = b.gradio), "label" in b && t(4, i = b.label), "legend_label" in b && t(5, o = b.legend_label), "info" in b && t(6, s = b.info), "elem_id" in b && t(7, f = b.elem_id), "elem_classes" in b && t(8, a = b.elem_classes), "visible" in b && t(9, _ = b.visible), "value" in b && t(0, r = b.value), "show_label" in b && t(10, u = b.show_label), "show_legend" in b && t(11, c = b.show_legend), "show_legend_label" in b && t(12, m = b.show_legend_label), "color_map" in b && t(1, k = b.color_map), "container" in b && t(13, j = b.container), "scale" in b && t(14, T = b.scale), "min_width" in b && t(15, S = b.min_width), "show_copy_button" in b && t(16, y = b.show_copy_button), "show_remove_tags_button" in b && t(17, d = b.show_remove_tags_button), "loading_status" in b && t(18, C = b.loading_status), "value_is_output" in b && t(2, L = b.value_is_output), "combine_adjacent" in b && t(20, h = b.combine_adjacent), "interactive" in b && t(19, Z = b.interactive);
3195
  }, l.$$.update = () => {
3196
  l.$$.dirty[0] & /*color_map*/
3197
  2 && !k && Object.keys(k).length && t(1, k), l.$$.dirty[0] & /*value, combine_adjacent*/
 
3199
  }, [
3200
  r,
3201
  k,
3202
+ L,
3203
  n,
3204
  i,
3205
  o,
 
3210
  u,
3211
  c,
3212
  m,
3213
+ j,
3214
  T,
3215
  S,
3216
  y,
src/demo/app.py CHANGED
@@ -100,6 +100,7 @@ Highlights will disappear if the highlighted text is edited. Modals will appear
100
  show_legend_label=True,
101
  show_remove_tags_button=True,
102
  show_copy_button=False,
 
103
  )
104
 
105
  # Functions
 
100
  show_legend_label=True,
101
  show_remove_tags_button=True,
102
  show_copy_button=False,
103
+ color_map={"Error A": "blue", "Error B": "red", "Error C": "green"},
104
  )
105
 
106
  # Functions
src/demo/space.py CHANGED
@@ -140,6 +140,7 @@ Highlights will disappear if the highlighted text is edited. Modals will appear
140
  show_legend_label=True,
141
  show_remove_tags_button=True,
142
  show_copy_button=False,
 
143
  )
144
 
145
  # Functions
@@ -169,11 +170,6 @@ Highlights will disappear if the highlighted text is edited. Modals will appear
169
  inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
170
  outputs=None,
171
  )
172
- high.change(
173
- fn=show_info,
174
- inputs=[high, tag_id, tag_open, tag_close, gr.State("Change")],
175
- outputs=None,
176
- )
177
 
178
  if __name__ == "__main__":
179
  demo.launch()
 
140
  show_legend_label=True,
141
  show_remove_tags_button=True,
142
  show_copy_button=False,
143
+ color_map={"Error A": "blue", "Error B": "red", "Error C": "green"},
144
  )
145
 
146
  # Functions
 
170
  inputs=[high, tag_id, tag_open, tag_close, gr.State("Remove tags")],
171
  outputs=None,
172
  )
 
 
 
 
 
173
 
174
  if __name__ == "__main__":
175
  demo.launch()
src/frontend/HighlightedTextbox.svelte CHANGED
@@ -29,7 +29,7 @@
29
  let el_text: string = "";
30
  let marked_el_text: string = "";
31
  let ctx: CanvasRenderingContext2D;
32
- let current_color_map: Record<string, string> = !color_map || Object.keys(color_map).length === 0 ? {} : color_map;
33
  let _color_map: Record<string, { primary: string; secondary: string }> = {};
34
  let copied = false;
35
  let tags_removed = false;
@@ -38,6 +38,7 @@
38
  let tagged_text: string = "";
39
 
40
  function set_color_map(): void {
 
41
  // if a label in the color map is not in the value, remove it from the color map
42
  for (let label in current_color_map) {
43
  if (!value.map(([_, label]) => label).includes(label)) {
 
29
  let el_text: string = "";
30
  let marked_el_text: string = "";
31
  let ctx: CanvasRenderingContext2D;
32
+ let current_color_map: Record<string, string>;
33
  let _color_map: Record<string, { primary: string; secondary: string }> = {};
34
  let copied = false;
35
  let tags_removed = false;
 
38
  let tagged_text: string = "";
39
 
40
  function set_color_map(): void {
41
+ current_color_map = !color_map || Object.keys(color_map).length === 0 ? {} : color_map;
42
  // if a label in the color map is not in the value, remove it from the color map
43
  for (let label in current_color_map) {
44
  if (!value.map(([_, label]) => label).includes(label)) {
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "gradio_highlightedtextbox"
11
- version = "0.0.10"
12
  description = "Editable Gradio textarea supporting highlighting"
13
  readme = "README.md"
14
  license = "MIT"
@@ -39,7 +39,7 @@ dev = ["build", "twine"]
39
  space = "https://huggingface.co/spaces/gsarti/gradio_highlightedtextbox"
40
 
41
  [tool.hatch.build]
42
- artifacts = ["/backend/gradio_highlightedtextbox/templates", "*.pyi", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "Users/gsarti/Documents/projects/highlightedtextbox/backend/gradio_highlightedtextbox/templates", "Users/gsarti/Documents/projects/highlightedtextbox/backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates"]
43
 
44
  [tool.hatch.build.targets.wheel]
45
  packages = ["/backend/gradio_highlightedtextbox"]
 
8
 
9
  [project]
10
  name = "gradio_highlightedtextbox"
11
+ version = "0.0.11"
12
  description = "Editable Gradio textarea supporting highlighting"
13
  readme = "README.md"
14
  license = "MIT"
 
39
  space = "https://huggingface.co/spaces/gsarti/gradio_highlightedtextbox"
40
 
41
  [tool.hatch.build]
42
+ artifacts = ["/backend/gradio_highlightedtextbox/templates", "*.pyi", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "Users/gsarti/Documents/projects/highlightedtextbox/backend/gradio_highlightedtextbox/templates", "Users/gsarti/Documents/projects/highlightedtextbox/backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates", "backend/gradio_highlightedtextbox/templates"]
43
 
44
  [tool.hatch.build.targets.wheel]
45
  packages = ["/backend/gradio_highlightedtextbox"]