Spaces:
Runtime error
Runtime error
spitzc32 commited on
Commit ·
d49d3a0
1
Parent(s): e45f1fa
added interactive widgets to api
Browse files
app.py
CHANGED
|
@@ -1,7 +1,25 @@
|
|
| 1 |
from model.layer import Bi_LSTM_CRF
|
| 2 |
from flair.data import Sentence
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
tagger = Bi_LSTM_CRF.load("checkpoints/best-model.pt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def model(word: str):
|
| 7 |
"""
|
|
@@ -23,4 +41,25 @@ def model(word: str):
|
|
| 23 |
"labels": labels,
|
| 24 |
"tags": tags
|
| 25 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from model.layer import Bi_LSTM_CRF
|
| 2 |
from flair.data import Sentence
|
| 3 |
+
import panel as pn
|
| 4 |
|
| 5 |
+
pn.extension()
|
| 6 |
+
pn.extension('tabulator')
|
| 7 |
+
import warnings
|
| 8 |
+
warnings.filterwarnings('ignore')
|
| 9 |
+
|
| 10 |
+
# Variables for Interactive selections
|
| 11 |
tagger = Bi_LSTM_CRF.load("checkpoints/best-model.pt")
|
| 12 |
+
text_widget = pn.widgets.TextAreaInput(height=300, name='Add text')
|
| 13 |
+
button = pn.widgets.Button(name="Click me to run!")
|
| 14 |
+
explanation = pn.pane.Markdown(
|
| 15 |
+
"""
|
| 16 |
+
## Redaction API
|
| 17 |
+
This app provides a text classification for a given text. To fully understand the redaction process,
|
| 18 |
+
given below is the classification of each text under the file we need the redaction on.
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
|
| 24 |
def model(word: str):
|
| 25 |
"""
|
|
|
|
| 41 |
"labels": labels,
|
| 42 |
"tags": tags
|
| 43 |
}
|
| 44 |
+
|
| 45 |
+
def get_tag_results(_):
|
| 46 |
+
return pn.Column(
|
| 47 |
+
explanation,
|
| 48 |
+
pn.pane.Markdown("""
|
| 49 |
+
##Results:"""),
|
| 50 |
+
model(text_widget.value.replace("\n", ""))
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
|
| 54 |
+
interactive = pn.bind(get_tag_results, button)
|
| 55 |
+
template = pn.template.FastListTemplate(
|
| 56 |
+
title='Model API',
|
| 57 |
+
sidebar=[
|
| 58 |
+
text_widget,
|
| 59 |
+
button,
|
| 60 |
+
],
|
| 61 |
+
main=[pn.panel(interactive, loading_indicator=True)],
|
| 62 |
+
accent_base_color="#88d8b0",
|
| 63 |
+
header_background="#88d8b0",
|
| 64 |
+
)
|
| 65 |
+
template.servable()
|