Spaces:
Runtime error
Runtime error
File size: 5,126 Bytes
88f59a8 1e00edb 88f59a8 6ed8aa7 f2ebfaa 0647140 88f59a8 f2ebfaa c1bfa56 1e00edb 0647140 f2ebfaa 88f59a8 f2ebfaa 1e00edb f2ebfaa 1e00edb c1bfa56 1e00edb 6ed8aa7 f2ebfaa 6ed8aa7 88f59a8 bf204d1 f2ebfaa 88f59a8 bf204d1 f2ebfaa d65d45a f2ebfaa 8de24c3 f2ebfaa 1e00edb bf204d1 f2ebfaa 1e00edb f2ebfaa 88f59a8 f2ebfaa a70af0f 59f2de4 88f59a8 6ed8aa7 88f59a8 f2ebfaa 88f59a8 0647140 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
import param
import panel as pn
pn.extension(sizing_mode="stretch_width", notifications=True)
import pickle
import pandas as pd
css = ['https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css',
# Below: Needed for export buttons
'https://cdn.datatables.net/buttons/1.7.0/css/buttons.dataTables.min.css'
]
js = {
'$': 'https://code.jquery.com/jquery-3.5.1.js',
'DataTable': 'https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js',
# Below: Needed for export buttons
'buttons': 'https://cdn.datatables.net/buttons/1.7.0/js/dataTables.buttons.min.js',
'jszip': 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js',
'pdfmake': 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js',
'vfsfonts': 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js',
'html5buttons': 'https://cdn.datatables.net/buttons/1.7.0/js/buttons.html5.min.js',
}
pn.extension(css_files=css, js_files=js)
script = """
<script>
if (document.readyState === "complete") {
$('.example').DataTable();
} else {
$(document).ready(function () {
$('.example').DataTable();
})
}
</script>
"""
import pandas as pd
class ReactiveTables(param.Parameterized):
the_word_for_finding_secret_languages = param.String('Asian')
old_data = None
@param.depends('the_word_for_finding_secret_languages')
def data(self):
print('new name', self.the_word_for_finding_secret_languages)
if len(self.the_word_for_finding_secret_languages) > 0:
if ord(self.the_word_for_finding_secret_languages[0]) in list(range(48, 57)):
file_name = 'num_dict.pkl'
elif ord(self.the_word_for_finding_secret_languages[0]) in list(range(97, 122)) + list(range(65, 90)):
file_name = f'{ord(self.the_word_for_finding_secret_languages[0])}_dict.pkl'
else:
file_name = 'other_dict.pkl'
print(f'all_secret_langauge_by_fist/{file_name}')
datas = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
flag = False
if self.the_word_for_finding_secret_languages in datas.keys():
self.old_data = pd.DataFrame(datas[self.the_word_for_finding_secret_languages])
flag = True
return self.old_data, datas, flag
# @param.depends('name_')
# def summary(self):
# return self.data()[0].describe()
@param.depends('the_word_for_finding_secret_languages')
def table_ours(self):
data, _, flag = self.data()
if flag:
all_secret_language = ' ,'.join([f'"{i}"' for i in set(list(data['secret languages']))]).replace('<s>', '[POS]')
all_examples = list(set(list('"' + data['original sentences'] + '" -> "' + data['replaced sentences'] + '"')))
samples = ' <br>'.join(all_examples[:10]).replace('<s>', '[POS]')
return pn.pane.HTML(
f'<h1>{self.the_word_for_finding_secret_languages}</h1><h1>All secret language for {self.the_word_for_finding_secret_languages}</h1>{all_secret_language}<h1>10 Examples for replaced sentences ("original sentences" -> "replaced sentences")</h1>{samples}',
sizing_mode='stretch_width')
else:
return pn.pane.HTML(f'<h1>Sorry. {self.the_word_for_finding_secret_languages} is not in the dictionary.</h1>' ,
sizing_mode='stretch_width')
# @param.depends('name_', 'record_start_index', 'record_stop_index')
# def notification(self):
# _, datas, flag = self.data()
# return_ =
# if datas:
# if flag:
# _len = len(datas[self.name_]['tasks'])
# return_ = pn.pane.HTML(f'<h1>Found {self.name_}.</h1> <h2> {self.name_} has {_len} secret languages found by SecretFinding. Presenting the secret languages from {self.record_start_index} to {min(self.record_stop_index, _len)}.</h2>' ,
# sizing_mode='stretch_width')
# else:
# return_ = pn.pane.HTML('<h1>initing</h1>' , sizing_mode='stretch_width')
# return return_
def panel(self):
return pn.Column(
pn.Param(self, name="", width=300, sizing_mode="stretch_width"),
# self.notification,
# "## Description", self.summary,
# "## Table",
self.table_ours,
# width=1500,
sizing_mode='stretch_width'
)
component = ReactiveTables().panel()
pn.template.FastListTemplate(site="ACL 23 Submission", title="Finding Secret Language of Language Models",
main=[
"This page presents all secret languages discovered by our proposed SecretFinding algorithm on three multi-sentence datasets. To ensure optimal performance of this webapp, we only present 10 examples.",
component
]).servable()
|