bowphs commited on
Commit
9fa77c4
1 Parent(s): 329698d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -39
app.py CHANGED
@@ -20,6 +20,7 @@ from models import (
20
  LabelRobertaForTokenClassification,
21
  )
22
 
 
23
  DEFAULT_TEXT = "τίω δέ μιν ἐν καρὸς αἴσῃ."
24
  BUTTON_CSS = "float: right; --tw-border-opacity: 1; border-color: rgb(229 231 235 / var(--tw-border-opacity)); --tw-gradient-from: rgb(243 244 246 / 0.7); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to, rgb(243 244 246 / 0)); --tw-gradient-to: rgb(229 231 235 / 0.8); --tw-text-opacity: 1; color: rgb(55 65 81 / var(--tw-text-opacity)); border-width: 1px; --tw-bg-opacity: 1; background-color: rgb(255 255 255 / var(--tw-bg-opacity)); background-image: linear-gradient(to bottom right, var(--tw-gradient-stops)); display: inline-flex; flex: 1 1 0%; align-items: center; justify-content: center; --tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); --tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color); box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); -webkit-appearance: button; border-radius: 0.5rem; padding-top: 0.5rem; padding-bottom: 0.5rem; padding-left: 1rem; padding-right: 1rem; font-size: 1rem; line-height: 1.5rem; font-weight: 600;"
25
  DEFAULT_COLOR = "white"
@@ -33,7 +34,6 @@ MODEL_PATHS = {
33
  MODEL_MAX_LENGTH = 512
34
 
35
  AUTH_TOKEN = os.environ.get("TOKEN") or True
36
-
37
  # PoS
38
  pos_tokenizer = AutoTokenizer.from_pretrained(
39
  MODEL_PATHS["POS"], model_max_length=MODEL_MAX_LENGTH, use_auth_token=AUTH_TOKEN, revision="8bd84df2bcaee089307fd604c80139a34ac71f12",
@@ -196,7 +196,7 @@ def parse(
196
  )["arcs"]
197
 
198
  options = {"compact": compact, "bg": bg, "color": text}
199
- svg = displacy.render(doc, manual=True, style="dep", options=options)
200
 
201
  if col_lemmata:
202
  soup = BeautifulSoup(svg, "lxml-xml")
@@ -207,26 +207,31 @@ def parse(
207
 
208
  return svg, download_link
209
 
 
210
  def setup_parser_ui():
211
- theme = gr.themes.Monochrome()
212
- with gr.Blocks(theme=theme) as demo:
213
- with gr.Group():
214
- gr.Markdown("# Athena's Lens")
215
- gr.Markdown(
216
- "### From Ἀlkaios to Ὠrigen: A Modern Lens on Timeless Texts"
217
- )
218
- with gr.Group():
219
- gr.Markdown("## Enter some text")
220
  with gr.Row():
221
- with gr.Column(scale=0.5):
222
- text_input = gr.Textbox(
223
- value=DEFAULT_TEXT, interactive=True, label="Input Text"
 
224
  )
225
- with gr.Row():
226
- with gr.Column(scale=0.25):
227
- button = gr.Button("Update", variant="primary")
228
-
229
- with gr.Group():
 
 
 
 
 
 
 
 
 
230
  with gr.Column():
231
  with gr.Row():
232
  with gr.Column():
@@ -242,7 +247,6 @@ def setup_parser_ui():
242
  bg = gr.Textbox(label="Background Color", value=DEFAULT_COLOR)
243
  with gr.Column():
244
  text = gr.Textbox(label="Text Color", value="black")
245
- with gr.Group():
246
  with gr.Row():
247
  dep_output = gr.HTML(
248
  value=parse(
@@ -254,16 +258,20 @@ def setup_parser_ui():
254
  False,
255
  DEFAULT_COLOR,
256
  "black",
257
- )[0]
 
258
  )
259
  with gr.Row():
260
- with gr.Column():
261
- dep_button = gr.Button("Update Parser", variant="primary")
 
 
262
  with gr.Column():
263
  dep_download_button = gr.HTML(
264
  value=download_svg(dep_output.value)
265
  )
266
- with gr.Group():
 
267
  with gr.Column():
268
  with gr.Row():
269
  with gr.Column():
@@ -277,21 +285,22 @@ def setup_parser_ui():
277
  )
278
  gr.Markdown(
279
  """```bibtex
280
- @incollection{riemenschneider-frank-2023-exploring,
281
- title = "Exploring Large Language Models for Classical Philology",
282
- author = "Riemenschneider, Frederick and Frank, Anette",
283
- booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
284
- month = jul,
285
- year = "2023",
286
- address = "Toronto, Canada",
287
- publisher = "Association for Computational Linguistics",
288
- url = "https://aclanthology.org/2023.acl-long.846",
289
- doi = "10.18653/v1/2023.acl-long.846",
290
- pages = "15181--15199",
291
- }
292
- ```
293
- """
294
  )
 
295
  button.click(
296
  execute_parse,
297
  inputs=[
@@ -324,7 +333,6 @@ def setup_parser_ui():
324
  return demo
325
 
326
 
327
-
328
  def main():
329
  demo = setup_parser_ui()
330
  demo.launch()
 
20
  LabelRobertaForTokenClassification,
21
  )
22
 
23
+
24
  DEFAULT_TEXT = "τίω δέ μιν ἐν καρὸς αἴσῃ."
25
  BUTTON_CSS = "float: right; --tw-border-opacity: 1; border-color: rgb(229 231 235 / var(--tw-border-opacity)); --tw-gradient-from: rgb(243 244 246 / 0.7); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to, rgb(243 244 246 / 0)); --tw-gradient-to: rgb(229 231 235 / 0.8); --tw-text-opacity: 1; color: rgb(55 65 81 / var(--tw-text-opacity)); border-width: 1px; --tw-bg-opacity: 1; background-color: rgb(255 255 255 / var(--tw-bg-opacity)); background-image: linear-gradient(to bottom right, var(--tw-gradient-stops)); display: inline-flex; flex: 1 1 0%; align-items: center; justify-content: center; --tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); --tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color); box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); -webkit-appearance: button; border-radius: 0.5rem; padding-top: 0.5rem; padding-bottom: 0.5rem; padding-left: 1rem; padding-right: 1rem; font-size: 1rem; line-height: 1.5rem; font-weight: 600;"
26
  DEFAULT_COLOR = "white"
 
34
  MODEL_MAX_LENGTH = 512
35
 
36
  AUTH_TOKEN = os.environ.get("TOKEN") or True
 
37
  # PoS
38
  pos_tokenizer = AutoTokenizer.from_pretrained(
39
  MODEL_PATHS["POS"], model_max_length=MODEL_MAX_LENGTH, use_auth_token=AUTH_TOKEN, revision="8bd84df2bcaee089307fd604c80139a34ac71f12",
 
196
  )["arcs"]
197
 
198
  options = {"compact": compact, "bg": bg, "color": text}
199
+ svg = displacy.render(doc, manual=True, options=options) #style="dep",
200
 
201
  if col_lemmata:
202
  soup = BeautifulSoup(svg, "lxml-xml")
 
207
 
208
  return svg, download_link
209
 
210
+
211
  def setup_parser_ui():
212
+ demo = gr.Blocks(css="scrollbar.css")
213
+ with demo:
214
+ with gr.Row():
 
 
 
 
 
 
215
  with gr.Row():
216
+ with gr.Column():
217
+ gr.Markdown("# Athena's Lens")
218
+ gr.Markdown(
219
+ "### From Ἀlkaios to Ὠrigen: A Modern Lens on Timeless Texts"
220
  )
221
+ with gr.Row():
222
+ with gr.Column():
223
+ gr.Markdown(" ## Enter some text")
224
+ with gr.Row():
225
+ with gr.Column(scale=0.5):
226
+ text_input = gr.Textbox(
227
+ value=DEFAULT_TEXT, interactive=True, label="Input Text"
228
+ )
229
+ with gr.Row():
230
+ with gr.Column(scale=0.25):
231
+ button = gr.Button("Update", variant="primary")#.style(
232
+ #full_width=False
233
+ #)
234
+ with gr.Row():
235
  with gr.Column():
236
  with gr.Row():
237
  with gr.Column():
 
247
  bg = gr.Textbox(label="Background Color", value=DEFAULT_COLOR)
248
  with gr.Column():
249
  text = gr.Textbox(label="Text Color", value="black")
 
250
  with gr.Row():
251
  dep_output = gr.HTML(
252
  value=parse(
 
258
  False,
259
  DEFAULT_COLOR,
260
  "black",
261
+ )[0],
262
+ elem_classes=["output-html"]
263
  )
264
  with gr.Row():
265
+ with gr.Column(scale=0.25):
266
+ dep_button = gr.Button(
267
+ "Update Parser", variant="primary"
268
+ )#.style(full_width=False)
269
  with gr.Column():
270
  dep_download_button = gr.HTML(
271
  value=download_svg(dep_output.value)
272
  )
273
+
274
+ with gr.Row():
275
  with gr.Column():
276
  with gr.Row():
277
  with gr.Column():
 
285
  )
286
  gr.Markdown(
287
  """```bibtex
288
+ @incollection{riemenschneider-frank-2023-exploring,
289
+ title = "Exploring Large Language Models for Classical Philology",
290
+ author = "Riemenschneider, Frederick and Frank, Anette",
291
+ booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
292
+ month = jul,
293
+ year = "2023",
294
+ address = "Toronto, Canada",
295
+ publisher = "Association for Computational Linguistics",
296
+ url = "https://aclanthology.org/2023.acl-long.846",
297
+ doi = "10.18653/v1/2023.acl-long.846",
298
+ pages = "15181--15199",
299
+ }
300
+ ```
301
+ """
302
  )
303
+
304
  button.click(
305
  execute_parse,
306
  inputs=[
 
333
  return demo
334
 
335
 
 
336
  def main():
337
  demo = setup_parser_ui()
338
  demo.launch()