cifkao commited on
Commit
19a8bac
1 Parent(s): ffa03c8

Improve UI

Browse files
app.py CHANGED
@@ -85,7 +85,10 @@ if not compact_layout:
85
  """
86
  )
87
 
88
- generation_mode = st.radio("Mode", ["Standard", "Generation"], horizontal=True) == "Generation"
 
 
 
89
  st.caption(
90
  "In standard mode, we analyze the model's predictions on the input text. "
91
  "In generation mode, we generate a continuation of the input text (prompt) "
@@ -120,29 +123,30 @@ max_tokens = int(MAX_MEM / (multiplier * window_len) - window_len)
120
  max_tokens = min(max_tokens, 4096)
121
 
122
  generate_kwargs = {}
123
- if generation_mode:
124
- with st.expander("Generation options", expanded=False):
125
- generate_kwargs["max_new_tokens"] = st.slider(
126
- "Max. number of generated tokens",
127
- min_value=8, max_value=min(1024, max_tokens), value=min(128, max_tokens)
128
- )
129
- col1, col2, col3, col4 = st.columns(4)
130
- with col1:
131
- generate_kwargs["temperature"] = st.number_input(
132
- min_value=0.01, value=0.9, step=0.05, label="`temperature`"
133
- )
134
- with col2:
135
- generate_kwargs["top_p"] = st.number_input(
136
- min_value=0., value=0.95, max_value=1., step=0.05, label="`top_p`"
137
- )
138
- with col3:
139
- generate_kwargs["typical_p"] = st.number_input(
140
- min_value=0., value=1., max_value=1., step=0.05, label="`typical_p`"
141
- )
142
- with col4:
143
- generate_kwargs["repetition_penalty"] = st.number_input(
144
- min_value=1., value=1., step=0.05, label="`repetition_penalty`"
145
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  DEFAULT_TEXT = """
148
  We present context length probing, a novel explanation technique for causal
@@ -154,11 +158,14 @@ and offer some initial analyses and insights, including the potential for studyi
154
  dependencies.
155
  """.replace("\n", " ").strip()
156
 
157
- text = st.text_area(
158
- f"Prompt" if generation_mode else "Input text (≤\u2009{max_tokens} tokens)",
159
- st.session_state.get("input_text", DEFAULT_TEXT),
160
- key="input_text",
161
- )
 
 
 
162
 
163
  inputs = tokenizer([text])
164
  [input_ids] = inputs["input_ids"]
@@ -316,6 +323,9 @@ def run_context_length_probing(
316
  if not generation_mode:
317
  run_context_length_probing = st.cache_data(run_context_length_probing, show_spinner=False)
318
 
 
 
 
319
  output_ids, scores = run_context_length_probing(
320
  _model=model,
321
  _tokenizer=tokenizer,
 
85
  """
86
  )
87
 
88
+ generation_mode = st.radio(
89
+ "Mode", ["Standard mode", "Generation mode"],
90
+ horizontal=True, label_visibility="collapsed"
91
+ ) == "Generation mode"
92
  st.caption(
93
  "In standard mode, we analyze the model's predictions on the input text. "
94
  "In generation mode, we generate a continuation of the input text (prompt) "
 
123
  max_tokens = min(max_tokens, 4096)
124
 
125
  generate_kwargs = {}
126
+ with st.empty():
127
+ if generation_mode:
128
+ with st.expander("Generation options", expanded=False):
129
+ generate_kwargs["max_new_tokens"] = st.slider(
130
+ "Max. number of generated tokens",
131
+ min_value=8, max_value=min(1024, max_tokens), value=min(128, max_tokens)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  )
133
+ col1, col2, col3, col4 = st.columns(4)
134
+ with col1:
135
+ generate_kwargs["temperature"] = st.number_input(
136
+ min_value=0.01, value=0.9, step=0.05, label="`temperature`"
137
+ )
138
+ with col2:
139
+ generate_kwargs["top_p"] = st.number_input(
140
+ min_value=0., value=0.95, max_value=1., step=0.05, label="`top_p`"
141
+ )
142
+ with col3:
143
+ generate_kwargs["typical_p"] = st.number_input(
144
+ min_value=0., value=1., max_value=1., step=0.05, label="`typical_p`"
145
+ )
146
+ with col4:
147
+ generate_kwargs["repetition_penalty"] = st.number_input(
148
+ min_value=1., value=1., step=0.05, label="`repetition_penalty`"
149
+ )
150
 
151
  DEFAULT_TEXT = """
152
  We present context length probing, a novel explanation technique for causal
 
158
  dependencies.
159
  """.replace("\n", " ").strip()
160
 
161
+ with st.expander(
162
+ f"Prompt" if generation_mode else f"Input text (≤\u2009{max_tokens} tokens)", expanded=True
163
+ ):
164
+ text = st.text_area(
165
+ "Input text",
166
+ st.session_state.get("input_text", DEFAULT_TEXT),
167
+ key="input_text", label_visibility="collapsed"
168
+ )
169
 
170
  inputs = tokenizer([text])
171
  [input_ids] = inputs["input_ids"]
 
323
  if not generation_mode:
324
  run_context_length_probing = st.cache_data(run_context_length_probing, show_spinner=False)
325
 
326
+ if generation_mode:
327
+ st.button("Rerun", type="primary")
328
+
329
  output_ids, scores = run_context_length_probing(
330
  _model=model,
331
  _tokenizer=tokenizer,
highlighted_text/build/asset-manifest.json CHANGED
@@ -1,20 +1,20 @@
1
  {
2
  "files": {
3
- "main.css": "./static/css/main.a84f16ea.chunk.css",
4
- "main.js": "./static/js/main.5f2b5265.chunk.js",
5
- "main.js.map": "./static/js/main.5f2b5265.chunk.js.map",
6
  "runtime-main.js": "./static/js/runtime-main.e6b0ae4c.js",
7
  "runtime-main.js.map": "./static/js/runtime-main.e6b0ae4c.js.map",
8
  "static/js/2.ce130e37.chunk.js": "./static/js/2.ce130e37.chunk.js",
9
  "static/js/2.ce130e37.chunk.js.map": "./static/js/2.ce130e37.chunk.js.map",
10
  "index.html": "./index.html",
11
- "static/css/main.a84f16ea.chunk.css.map": "./static/css/main.a84f16ea.chunk.css.map",
12
  "static/js/2.ce130e37.chunk.js.LICENSE.txt": "./static/js/2.ce130e37.chunk.js.LICENSE.txt"
13
  },
14
  "entrypoints": [
15
  "static/js/runtime-main.e6b0ae4c.js",
16
  "static/js/2.ce130e37.chunk.js",
17
- "static/css/main.a84f16ea.chunk.css",
18
- "static/js/main.5f2b5265.chunk.js"
19
  ]
20
  }
 
1
  {
2
  "files": {
3
+ "main.css": "./static/css/main.1ea17946.chunk.css",
4
+ "main.js": "./static/js/main.34cd70dc.chunk.js",
5
+ "main.js.map": "./static/js/main.34cd70dc.chunk.js.map",
6
  "runtime-main.js": "./static/js/runtime-main.e6b0ae4c.js",
7
  "runtime-main.js.map": "./static/js/runtime-main.e6b0ae4c.js.map",
8
  "static/js/2.ce130e37.chunk.js": "./static/js/2.ce130e37.chunk.js",
9
  "static/js/2.ce130e37.chunk.js.map": "./static/js/2.ce130e37.chunk.js.map",
10
  "index.html": "./index.html",
11
+ "static/css/main.1ea17946.chunk.css.map": "./static/css/main.1ea17946.chunk.css.map",
12
  "static/js/2.ce130e37.chunk.js.LICENSE.txt": "./static/js/2.ce130e37.chunk.js.LICENSE.txt"
13
  },
14
  "entrypoints": [
15
  "static/js/runtime-main.e6b0ae4c.js",
16
  "static/js/2.ce130e37.chunk.js",
17
+ "static/css/main.1ea17946.chunk.css",
18
+ "static/js/main.34cd70dc.chunk.js"
19
  ]
20
  }
highlighted_text/build/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><title>Highlighted text component</title><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="description" content="Highlighted text"/><link href="./static/css/main.a84f16ea.chunk.css" rel="stylesheet"></head><body><div id="root"></div><script>!function(e){function t(t){for(var n,l,a=t[0],p=t[1],i=t[2],c=0,s=[];c<a.length;c++)l=a[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in p)Object.prototype.hasOwnProperty.call(p,n)&&(e[n]=p[n]);for(f&&f(t);s.length;)s.shift()();return u.push.apply(u,i||[]),r()}function r(){for(var e,t=0;t<u.length;t++){for(var r=u[t],n=!0,a=1;a<r.length;a++){var p=r[a];0!==o[p]&&(n=!1)}n&&(u.splice(t--,1),e=l(l.s=r[0]))}return e}var n={},o={1:0},u=[];function l(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,l),r.l=!0,r.exports}l.m=e,l.c=n,l.d=function(e,t,r){l.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,t){if(1&t&&(e=l(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(l.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)l.d(r,n,function(t){return e[t]}.bind(null,n));return r},l.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(t,"a",t),t},l.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},l.p="./";var a=this.webpackJsonpstreamlit_component_template=this.webpackJsonpstreamlit_component_template||[],p=a.push.bind(a);a.push=t,a=a.slice();for(var i=0;i<a.length;i++)t(a[i]);var f=p;r()}([])</script><script src="./static/js/2.ce130e37.chunk.js"></script><script src="./static/js/main.5f2b5265.chunk.js"></script></body></html>
 
1
+ <!doctype html><html lang="en"><head><title>Highlighted text component</title><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="description" content="Highlighted text"/><link href="./static/css/main.1ea17946.chunk.css" rel="stylesheet"></head><body><div id="root"></div><script>!function(e){function t(t){for(var n,l,a=t[0],p=t[1],i=t[2],c=0,s=[];c<a.length;c++)l=a[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in p)Object.prototype.hasOwnProperty.call(p,n)&&(e[n]=p[n]);for(f&&f(t);s.length;)s.shift()();return u.push.apply(u,i||[]),r()}function r(){for(var e,t=0;t<u.length;t++){for(var r=u[t],n=!0,a=1;a<r.length;a++){var p=r[a];0!==o[p]&&(n=!1)}n&&(u.splice(t--,1),e=l(l.s=r[0]))}return e}var n={},o={1:0},u=[];function l(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,l),r.l=!0,r.exports}l.m=e,l.c=n,l.d=function(e,t,r){l.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,t){if(1&t&&(e=l(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(l.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)l.d(r,n,function(t){return e[t]}.bind(null,n));return r},l.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(t,"a",t),t},l.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},l.p="./";var a=this.webpackJsonpstreamlit_component_template=this.webpackJsonpstreamlit_component_template||[],p=a.push.bind(a);a.push=t,a=a.slice();for(var i=0;i<a.length;i++)t(a[i]);var f=p;r()}([])</script><script src="./static/js/2.ce130e37.chunk.js"></script><script src="./static/js/main.34cd70dc.chunk.js"></script></body></html>
highlighted_text/build/static/css/main.1ea17946.chunk.css ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ body{padding:0;margin:0;font-family:"Source Sans Pro",sans-serif;font-size:1rem;line-height:1.4}.container{border:1px solid #d2d2d2;border-radius:5px;padding:12px 16px}.highlighted-text,.status-bar{color:#000;background-color:#fff}.highlighted-text{background-color:#fefefe;border:1px solid rgba(49,51,63,.2);border-radius:5px;padding:5px;cursor:pointer}.highlighted-text .token.prefix~.token:not(.prefix){color:#2563eb}.highlighted-text .token.active{outline:1px solid #444}.status-bar{min-height:1.4em;padding-bottom:12px}.status-bar .token{border:1px solid #aaa;border-radius:2px;background:#f5f5f5;padding:1px;margin:1px 2px 1px 1px}
2
+ /*# sourceMappingURL=main.1ea17946.chunk.css.map */
highlighted_text/build/static/css/main.1ea17946.chunk.css.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"sources":["webpack://src/index.scss"],"names":[],"mappings":"AAAA,KACI,SAAA,CACA,QAAA,CACA,wCAAA,CACA,cAAA,CACA,eAAA,CAGJ,WACI,wBAAA,CACA,iBAAA,CACA,iBAAA,CAGJ,8BACI,UAAA,CACA,qBAAA,CAGJ,kBACI,wBAAA,CACA,kCAAA,CACA,iBAAA,CACA,WAAA,CACA,cAAA,CAEA,oDACI,aAAA,CAGJ,gCACI,sBAAA,CAIR,YACI,gBAAA,CACA,mBAAA,CAEA,mBACI,qBAAA,CACA,iBAAA,CACA,kBAAA,CACA,WAAA,CAEA,sBAAA","file":"main.1ea17946.chunk.css","sourcesContent":["body {\n padding: 0;\n margin: 0;\n font-family: \"Source Sans Pro\", sans-serif;\n font-size: 1rem;\n line-height: 1.4;\n}\n\n.container {\n border: 1px solid #d2d2d2;\n border-radius: 5px;\n padding: 12px 16px 12px 16px;\n}\n\n.highlighted-text, .status-bar {\n color: black;\n background-color: white;\n}\n\n.highlighted-text {\n background-color: #fefefe;\n border: 1px solid #31333f33;\n border-radius: 5px;\n padding: 5px;\n cursor: pointer;\n\n .token.prefix ~ .token:not(.prefix) {\n color: #2563eb;\n }\n\n .token.active {\n outline: 1px solid #444;\n }\n}\n\n.status-bar {\n min-height: 1.4em;\n padding-bottom: 12px;\n\n .token {\n border: 1px solid #aaa;\n border-radius: 2px;\n background: #f5f5f5;\n padding: 1px;\n margin: 1px;\n margin-right: 2px;\n }\n}\n"]}
highlighted_text/build/static/css/main.a84f16ea.chunk.css DELETED
@@ -1,2 +0,0 @@
1
- body{padding:0;margin:0;font-family:"Source Sans Pro",sans-serif;font-size:1rem;line-height:1.4}.highlighted-text,.status-bar{color:#000;background-color:#fff}.highlighted-text{border:1px solid #d2d2d2;border-radius:0 0 5px 5px;padding:4px;cursor:pointer}.highlighted-text .token.prefix~.token:not(.prefix){color:#2563eb}.highlighted-text .token.active{outline:1px solid #444}.status-bar{min-height:1.4em;border:1px solid #d2d2d2;border-bottom:none;border-radius:5px 5px 0 0;padding:3px 4px}.status-bar .token{border:1px solid #aaa;border-radius:2px;background:#f5f5f5;padding:1px;margin:1px 2px 1px 1px}
2
- /*# sourceMappingURL=main.a84f16ea.chunk.css.map */
 
 
 
highlighted_text/build/static/css/main.a84f16ea.chunk.css.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["webpack://src/index.scss"],"names":[],"mappings":"AAAA,KACI,SAAA,CACA,QAAA,CACA,wCAAA,CACA,cAAA,CACA,eAAA,CAGJ,8BACI,UAAA,CACA,qBAAA,CAGJ,kBACI,wBAAA,CACA,yBAAA,CACA,WAAA,CACA,cAAA,CAEA,oDACI,aAAA,CAGJ,gCACI,sBAAA,CAIR,YACI,gBAAA,CAEA,wBAAA,CAAA,kBAAA,CACA,yBAAA,CACA,eAAA,CAEA,mBACI,qBAAA,CACA,iBAAA,CACA,kBAAA,CACA,WAAA,CAEA,sBAAA","file":"main.a84f16ea.chunk.css","sourcesContent":["body {\n padding: 0;\n margin: 0;\n font-family: \"Source Sans Pro\", sans-serif;\n font-size: 1rem;\n line-height: 1.4;\n}\n\n.highlighted-text, .status-bar {\n color: black;\n background-color: white;\n}\n\n.highlighted-text {\n border: 1px solid #d2d2d2;\n border-radius: 0 0 5px 5px;\n padding: 4px;\n cursor: pointer;\n\n .token.prefix ~ .token:not(.prefix) {\n color: #2563eb;\n }\n\n .token.active {\n outline: 1px solid #444;\n }\n}\n\n.status-bar {\n min-height: 1.4em;\n border: 1px solid #d2d2d2;\n border-bottom: none;\n border-radius: 5px 5px 0 0;\n padding: 3px 4px;\n\n .token {\n border: 1px solid #aaa;\n border-radius: 2px;\n background: #f5f5f5;\n padding: 1px;\n margin: 1px;\n margin-right: 2px;\n }\n}\n"]}
 
 
highlighted_text/build/static/js/main.34cd70dc.chunk.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ (this.webpackJsonpstreamlit_component_template=this.webpackJsonpstreamlit_component_template||[]).push([[0],{27:function(t,e,a){},28:function(t,e,a){"use strict";a.r(e);var n=a(7),s=a.n(n),r=a(18),c=a.n(r),i=a(4),o=a(0),l=a(1),h=a(2),d=a(3),j=a(16),u=a(6),x=function(t){Object(h.a)(a,t);var e=Object(d.a)(a);function a(){var t;Object(o.a)(this,a);for(var n=arguments.length,s=new Array(n),r=0;r<n;r++)s[r]=arguments[r];return(t=e.call.apply(e,[this].concat(s))).state={activeIndex:null,hoverIndex:null,isFrozen:!1},t}return Object(l.a)(a,[{key:"render",value:function(){var t=this,e=this.props.args.tokens,a=this.getScores(),n=this.props.args.prefix_len,s="highlighted-text";this.state.isFrozen&&(s+=" frozen");var r=function(){t.setState({isFrozen:!1})};return Object(u.jsxs)("div",{className:"container",children:[Object(u.jsxs)("div",{className:"status-bar",children:[Object(u.jsxs)("span",{className:this.state.isFrozen?"":" d-none",children:[Object(u.jsx)("i",{className:"fa fa-lock"})," "]},"lock-icon"),null!=this.state.activeIndex?Object(u.jsxs)(u.Fragment,{children:[Object(u.jsx)("strong",{children:"index:"},"index-label")," ",Object(u.jsxs)("span",{children:[this.state.activeIndex," "]},"index")]}):Object(u.jsx)(u.Fragment,{})]},"status-bar"),Object(u.jsx)("div",{className:s,onClick:r,children:e.map((function(e,s){var c="token";t.state&&t.state.activeIndex==s&&(c+=" active"),s<n&&(c+=" prefix");var i={backgroundColor:a[s]>0?"rgba(32, 255, 32, ".concat(a[s],")"):"rgba(255, 32, 32, ".concat(-a[s],")")};return Object(u.jsx)("span",{className:c,style:i,onMouseOver:function(){t.state.isFrozen||t.setState({activeIndex:s}),t.setState({hoverIndex:s})},onClick:r,children:e},s)}))},"text")]})}},{key:"getScores",value:function(){var t=this.props.args.tokens;if(!this.state||null==this.state.activeIndex||this.state.activeIndex<1)return t.map((function(){return 0}));var e=this.props.args.scores,a=this.state.activeIndex-1,n=Math.min(Math.max(0,a),e[a].length),s=e[a].slice(0,n);s.reverse();var r=[].concat(Object(i.a)(Array(Math.max(0,a-s.length)).fill(0)),Object(i.a)(s.map((function(t){return void 0==t||isNaN(t)?0:t}))));return r=[].concat(Object(i.a)(r),Object(i.a)(Array(t.length-r.length).fill(0)))}}]),a}(j.a),b=Object(j.b)(x);a(27);c.a.render(Object(u.jsx)(s.a.StrictMode,{children:Object(u.jsx)(b,{})}),document.getElementById("root"))}},[[28,1,2]]]);
2
+ //# sourceMappingURL=main.34cd70dc.chunk.js.map
highlighted_text/build/static/js/main.34cd70dc.chunk.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"sources":["HighlightedText.tsx","index.tsx"],"names":["HighlightedText","_StreamlitComponentBa","_inherits","_super","_createSuper","_this","_classCallCheck","_len","arguments","length","args","Array","_key","call","apply","concat","state","activeIndex","hoverIndex","isFrozen","_createClass","key","value","_this2","tokens","this","props","scores","getScores","prefixLength","className","onClick","setState","_jsxs","children","_jsx","_Fragment","map","t","i","style","backgroundColor","onMouseOver","allScores","hi","Math","min","max","row","slice","reverse","result","_toConsumableArray","fill","x","undefined","isNaN","StreamlitComponentBase","withStreamlitConnection","ReactDOM","render","React","StrictMode","document","getElementById"],"mappings":"gQAeMA,EAAe,SAAAC,GAAAC,YAAAF,EAAAC,GAAA,IAAAE,EAAAC,YAAAJ,GAAA,SAAAA,IAAA,IAAAK,EAAAC,YAAA,KAAAN,GAAA,QAAAO,EAAAC,UAAAC,OAAAC,EAAA,IAAAC,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAAF,EAAAE,GAAAJ,UAAAI,GACqD,OADrDP,EAAAF,EAAAU,KAAAC,MAAAX,EAAA,OAAAY,OAAAL,KACVM,MAAQ,CAACC,YAAa,KAAMC,WAAY,KAAMC,UAAU,GAAMd,CAAC,CA6ErE,OA7EoEe,YAAApB,EAAA,EAAAqB,IAAA,SAAAC,MAErE,WAAU,IAADC,EAAA,KACCC,EAAmBC,KAAKC,MAAMhB,KAAa,OAC3CiB,EAAmBF,KAAKG,YACxBC,EAAuBJ,KAAKC,MAAMhB,KAAiB,WAErDoB,EAAY,mBACZL,KAAKT,MAAMG,WACXW,GAAa,WAGjB,IAAMC,EAAU,WACZR,EAAKS,SAAS,CAAEb,UAAU,GAC9B,EAEA,OAAOc,eAAA,OAAKH,UAAU,YAAWI,SAAA,CAC7BD,eAAA,OAAKH,UAAU,aAAYI,SAAA,CACvBD,eAAA,QAAMH,UAAWL,KAAKT,MAAMG,SAAW,GAAK,UAAU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,IAAI,EAAGR,EAAIS,EAAIvC,SAAS4C,KAAK,IAAED,YAC1CJ,EAAIX,KAAI,SAACiB,GAAC,YAAUC,GAALD,GAAkBE,MAAMF,GAAK,EAAIA,CAAC,MAGxD,OADAH,EAAM,GAAApC,OAAAqC,YAAOD,GAAMC,YAAKzC,MAAMa,EAAOf,OAAS0C,EAAO1C,QAAQ4C,KAAK,IAEtE,KAACrD,CAAA,CA9EgB,CAASyD,KAiFfC,cAAwB1D,G,MC3FvC2D,IAASC,OACPzB,cAAC0B,IAAMC,WAAU,CAAA5B,SACfC,cAACnC,EAAe,MAElB+D,SAASC,eAAe,Q","file":"static/js/main.34cd70dc.chunk.js","sourcesContent":["import {\n StreamlitComponentBase,\n withStreamlitConnection,\n} from \"streamlit-component-lib\";\n\ntype HighlightedTextState = {\n activeIndex: number | null,\n hoverIndex: number | null,\n isFrozen: boolean\n};\n\n/**\n * This is a React-based component template. The `render()` function is called\n * automatically when your component should be re-rendered.\n */\nclass HighlightedText extends StreamlitComponentBase<HighlightedTextState> {\n public state = {activeIndex: null, hoverIndex: null, isFrozen: false};\n\n render() {\n const tokens: string[] = this.props.args[\"tokens\"];\n const scores: number[] = this.getScores();\n const prefixLength: number = this.props.args[\"prefix_len\"];\n\n let className = \"highlighted-text\";\n if (this.state.isFrozen) {\n className += \" frozen\";\n }\n\n const onClick = () => {\n this.setState({ isFrozen: false });\n };\n\n return <div className=\"container\">\n <div className=\"status-bar\" key=\"status-bar\">\n <span className={this.state.isFrozen ? \"\" : \" d-none\"} key=\"lock-icon\"><i className=\"fa fa-lock\"></i> </span>\n {\n this.state.activeIndex != null ?\n <>\n <strong key=\"index-label\">index:</strong> <span key=\"index\">{this.state.activeIndex} </span>\n </>\n : <></>\n }\n </div>\n <div className={className} onClick={onClick} key=\"text\">\n {\n tokens.map((t: string, i: number) => {\n let className = \"token\";\n if (this.state) {\n if (this.state.activeIndex == i) {\n className += \" active\";\n }\n }\n if (i < prefixLength) {\n className += \" prefix\";\n }\n const style = {\n backgroundColor:\n scores[i] > 0\n ? `rgba(32, 255, 32, ${scores[i]})`\n : `rgba(255, 32, 32, ${-scores[i]})`\n };\n\n const onMouseOver = () => {\n if (!this.state.isFrozen) {\n this.setState({ activeIndex: i });\n }\n this.setState({ hoverIndex: i });\n };\n return <span key={i} className={className} style={style}\n onMouseOver={onMouseOver} onClick={onClick}>{t}</span>;\n })\n }\n </div>\n </div>;\n }\n\n private getScores() {\n const tokens = this.props.args[\"tokens\"];\n if (!this.state || this.state.activeIndex == null || this.state.activeIndex < 1) {\n return tokens.map(() => 0);\n }\n const allScores: number[][] = this.props.args[\"scores\"];\n\n const i = this.state.activeIndex - 1;\n const hi = Math.min(Math.max(0, i), allScores[i].length);\n const row = allScores[i].slice(0, hi);\n row.reverse();\n let result = [\n ...Array(Math.max(0, i - row.length)).fill(0),\n ...row.map((x) => x == undefined || isNaN(x) ? 0 : x)\n ];\n result = [...result, ...Array(tokens.length - result.length).fill(0)];\n return result;\n }\n}\n\nexport default withStreamlitConnection(HighlightedText);\n","import React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport HighlightedText from \"./HighlightedText\";\nimport \"./index.scss\";\n\nReactDOM.render(\n <React.StrictMode>\n <HighlightedText />\n </React.StrictMode>,\n document.getElementById(\"root\")\n)\n"],"sourceRoot":""}
highlighted_text/build/static/js/main.5f2b5265.chunk.js DELETED
@@ -1,2 +0,0 @@
1
- (this.webpackJsonpstreamlit_component_template=this.webpackJsonpstreamlit_component_template||[]).push([[0],{27:function(t,e,n){},28:function(t,e,n){"use strict";n.r(e);var a=n(7),s=n.n(a),r=n(18),c=n.n(r),i=n(4),o=n(0),l=n(1),h=n(2),d=n(3),j=n(16),u=n(6),x=function(t){Object(h.a)(n,t);var e=Object(d.a)(n);function n(){var t;Object(o.a)(this,n);for(var a=arguments.length,s=new Array(a),r=0;r<a;r++)s[r]=arguments[r];return(t=e.call.apply(e,[this].concat(s))).state={activeIndex:null,hoverIndex:null,isFrozen:!1},t}return Object(l.a)(n,[{key:"render",value:function(){var t=this,e=this.props.args.tokens,n=this.getScores(),a=this.props.args.prefix_len,s="highlighted-text";this.state.isFrozen&&(s+=" frozen");var r=function(){t.setState({isFrozen:!1})};return Object(u.jsxs)(u.Fragment,{children:[Object(u.jsxs)("div",{className:"status-bar",children:[Object(u.jsxs)("span",{className:this.state.isFrozen?"":" d-none",children:[Object(u.jsx)("i",{className:"fa fa-lock"})," "]},"lock-icon"),null!=this.state.activeIndex?Object(u.jsxs)(u.Fragment,{children:[Object(u.jsx)("strong",{children:"index:"},"index-label")," ",Object(u.jsxs)("span",{children:[this.state.activeIndex," "]},"index")]}):Object(u.jsx)(u.Fragment,{})]},"status-bar"),Object(u.jsx)("div",{className:s,onClick:r,children:e.map((function(e,s){var c="token";t.state&&t.state.activeIndex==s&&(c+=" active"),s<a&&(c+=" prefix");var i={backgroundColor:n[s]>0?"rgba(32, 255, 32, ".concat(n[s],")"):"rgba(255, 32, 32, ".concat(-n[s],")")};return Object(u.jsx)("span",{className:c,style:i,onMouseOver:function(){t.state.isFrozen||t.setState({activeIndex:s}),t.setState({hoverIndex:s})},onClick:r,children:e},s)}))},"text")]})}},{key:"getScores",value:function(){var t=this.props.args.tokens;if(!this.state||null==this.state.activeIndex||this.state.activeIndex<1)return t.map((function(){return 0}));var e=this.props.args.scores,n=this.state.activeIndex-1,a=Math.min(Math.max(0,n),e[n].length),s=e[n].slice(0,a);s.reverse();var r=[].concat(Object(i.a)(Array(Math.max(0,n-s.length)).fill(0)),Object(i.a)(s.map((function(t){return void 0==t||isNaN(t)?0:t}))));return r=[].concat(Object(i.a)(r),Object(i.a)(Array(t.length-r.length).fill(0)))}}]),n}(j.a),b=Object(j.b)(x);n(27);c.a.render(Object(u.jsx)(s.a.StrictMode,{children:Object(u.jsx)(b,{})}),document.getElementById("root"))}},[[28,1,2]]]);
2
- //# sourceMappingURL=main.5f2b5265.chunk.js.map
 
 
 
highlighted_text/build/static/js/main.5f2b5265.chunk.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["HighlightedText.tsx","index.tsx"],"names":["HighlightedText","_StreamlitComponentBa","_inherits","_super","_createSuper","_this","_classCallCheck","_len","arguments","length","args","Array","_key","call","apply","concat","state","activeIndex","hoverIndex","isFrozen","_createClass","key","value","_this2","tokens","this","props","scores","getScores","prefixLength","className","onClick","setState","_jsxs","_Fragment","children","_jsx","map","t","i","style","backgroundColor","onMouseOver","allScores","hi","Math","min","max","row","slice","reverse","result","_toConsumableArray","fill","x","undefined","isNaN","StreamlitComponentBase","withStreamlitConnection","ReactDOM","render","React","StrictMode","document","getElementById"],"mappings":"gQAeMA,EAAe,SAAAC,GAAAC,YAAAF,EAAAC,GAAA,IAAAE,EAAAC,YAAAJ,GAAA,SAAAA,IAAA,IAAAK,EAAAC,YAAA,KAAAN,GAAA,QAAAO,EAAAC,UAAAC,OAAAC,EAAA,IAAAC,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAAF,EAAAE,GAAAJ,UAAAI,GACqD,OADrDP,EAAAF,EAAAU,KAAAC,MAAAX,EAAA,OAAAY,OAAAL,KACVM,MAAQ,CAACC,YAAa,KAAMC,WAAY,KAAMC,UAAU,GAAMd,CAAC,CA6ErE,OA7EoEe,YAAApB,EAAA,EAAAqB,IAAA,SAAAC,MAErE,WAAU,IAADC,EAAA,KACCC,EAAmBC,KAAKC,MAAMhB,KAAa,OAC3CiB,EAAmBF,KAAKG,YACxBC,EAAeJ,KAAKC,MAAMhB,KAAiB,WAE7CoB,EAAY,mBACZL,KAAKT,MAAMG,WACXW,GAAa,WAGjB,IAAMC,EAAU,WACZR,EAAKS,SAAS,CAAEb,UAAU,GAC9B,EAEA,OAAOc,eAAAC,WAAA,CAAAC,SAAA,CACHF,eAAA,OAAKH,UAAU,aAAYK,SAAA,CACvBF,eAAA,QAAMH,UAAWL,KAAKT,MAAMG,SAAW,GAAK,UAAUgB,SAAA,CAAiBC,cAAA,KAAGN,UAAU,eAAiB,MAA1C,a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C1CJ,EAAIX,KAAI,SAACiB,GAAC,YAAUC,GAALD,GAAkBE,MAAMF,GAAK,EAAIA,CAAC,MAGxD,OADAH,EAAM,GAAApC,OAAAqC,YAAOD,GAAMC,YAAKzC,MAAMa,EAAOf,OAAS0C,EAAO1C,QAAQ4C,KAAK,IAEtE,KAACrD,CAAA,CA9EgB,CAASyD,KAiFfC,cAAwB1D,G,MC3FvC2D,IAASC,OACPxB,cAACyB,IAAMC,WAAU,CAAA3B,SACfC,cAACpC,EAAe,MAElB+D,SAASC,eAAe,Q","file":"static/js/main.5f2b5265.chunk.js","sourcesContent":["import {\n StreamlitComponentBase,\n withStreamlitConnection,\n} from \"streamlit-component-lib\";\n\ntype HighlightedTextState = {\n activeIndex: number | null,\n hoverIndex: number | null,\n isFrozen: boolean\n};\n\n/**\n * This is a React-based component template. The `render()` function is called\n * automatically when your component should be re-rendered.\n */\nclass HighlightedText extends StreamlitComponentBase<HighlightedTextState> {\n public state = {activeIndex: null, hoverIndex: null, isFrozen: false};\n\n render() {\n const tokens: string[] = this.props.args[\"tokens\"];\n const scores: number[] = this.getScores();\n const prefixLength = this.props.args[\"prefix_len\"];\n\n let className = \"highlighted-text\";\n if (this.state.isFrozen) {\n className += \" frozen\";\n }\n\n const onClick = () => {\n this.setState({ isFrozen: false });\n };\n\n return <>\n <div className=\"status-bar\" key=\"status-bar\">\n <span className={this.state.isFrozen ? \"\" : \" d-none\"} key=\"lock-icon\"><i className=\"fa fa-lock\"></i> </span>\n {\n this.state.activeIndex != null ?\n <>\n <strong key=\"index-label\">index:</strong> <span key=\"index\">{this.state.activeIndex} </span>\n </>\n : <></>\n }\n </div>\n <div className={className} onClick={onClick} key=\"text\">\n {\n tokens.map((t: string, i: number) => {\n let className = \"token\";\n if (this.state) {\n if (this.state.activeIndex == i) {\n className += \" active\";\n }\n }\n if (i < prefixLength) {\n className += \" prefix\";\n }\n const style = {\n backgroundColor:\n scores[i] > 0\n ? `rgba(32, 255, 32, ${scores[i]})`\n : `rgba(255, 32, 32, ${-scores[i]})`\n };\n\n const onMouseOver = () => {\n if (!this.state.isFrozen) {\n this.setState({ activeIndex: i });\n }\n this.setState({ hoverIndex: i });\n };\n return <span key={i} className={className} style={style}\n onMouseOver={onMouseOver} onClick={onClick}>{t}</span>;\n })\n }\n </div>\n </>;\n }\n\n private getScores() {\n const tokens = this.props.args[\"tokens\"];\n if (!this.state || this.state.activeIndex == null || this.state.activeIndex < 1) {\n return tokens.map(() => 0);\n }\n const allScores: number[][] = this.props.args[\"scores\"];\n\n const i = this.state.activeIndex - 1;\n const hi = Math.min(Math.max(0, i), allScores[i].length);\n const row = allScores[i].slice(0, hi);\n row.reverse();\n let result = [\n ...Array(Math.max(0, i - row.length)).fill(0),\n ...row.map((x) => x == undefined || isNaN(x) ? 0 : x)\n ];\n result = [...result, ...Array(tokens.length - result.length).fill(0)];\n return result;\n }\n}\n\nexport default withStreamlitConnection(HighlightedText);\n","import React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport HighlightedText from \"./HighlightedText\";\nimport \"./index.scss\";\n\nReactDOM.render(\n <React.StrictMode>\n <HighlightedText />\n </React.StrictMode>,\n document.getElementById(\"root\")\n)\n"],"sourceRoot":""}
 
 
highlighted_text/src/HighlightedText.tsx CHANGED
@@ -30,7 +30,7 @@ class HighlightedText extends StreamlitComponentBase<HighlightedTextState> {
30
  this.setState({ isFrozen: false });
31
  };
32
 
33
- return <>
34
  <div className="status-bar" key="status-bar">
35
  <span className={this.state.isFrozen ? "" : " d-none"} key="lock-icon"><i className="fa fa-lock"></i> </span>
36
  {
@@ -71,7 +71,7 @@ class HighlightedText extends StreamlitComponentBase<HighlightedTextState> {
71
  })
72
  }
73
  </div>
74
- </>;
75
  }
76
 
77
  private getScores() {
 
30
  this.setState({ isFrozen: false });
31
  };
32
 
33
+ return <div className="container">
34
  <div className="status-bar" key="status-bar">
35
  <span className={this.state.isFrozen ? "" : " d-none"} key="lock-icon"><i className="fa fa-lock"></i> </span>
36
  {
 
71
  })
72
  }
73
  </div>
74
+ </div>;
75
  }
76
 
77
  private getScores() {
highlighted_text/src/index.scss CHANGED
@@ -6,15 +6,22 @@ body {
6
  line-height: 1.4;
7
  }
8
 
 
 
 
 
 
 
9
  .highlighted-text, .status-bar {
10
  color: black;
11
  background-color: white;
12
  }
13
 
14
  .highlighted-text {
15
- border: 1px solid #d2d2d2;
16
- border-radius: 0 0 5px 5px;
17
- padding: 4px;
 
18
  cursor: pointer;
19
 
20
  .token.prefix ~ .token:not(.prefix) {
@@ -28,10 +35,7 @@ body {
28
 
29
  .status-bar {
30
  min-height: 1.4em;
31
- border: 1px solid #d2d2d2;
32
- border-bottom: none;
33
- border-radius: 5px 5px 0 0;
34
- padding: 3px 4px;
35
 
36
  .token {
37
  border: 1px solid #aaa;
 
6
  line-height: 1.4;
7
  }
8
 
9
+ .container {
10
+ border: 1px solid #d2d2d2;
11
+ border-radius: 5px;
12
+ padding: 12px 16px 12px 16px;
13
+ }
14
+
15
  .highlighted-text, .status-bar {
16
  color: black;
17
  background-color: white;
18
  }
19
 
20
  .highlighted-text {
21
+ background-color: #fefefe;
22
+ border: 1px solid #31333f33;
23
+ border-radius: 5px;
24
+ padding: 5px;
25
  cursor: pointer;
26
 
27
  .token.prefix ~ .token:not(.prefix) {
 
35
 
36
  .status-bar {
37
  min-height: 1.4em;
38
+ padding-bottom: 12px;
 
 
 
39
 
40
  .token {
41
  border: 1px solid #aaa;