imvladikon commited on
Commit
44ad8f1
1 Parent(s): 90a10bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -14,7 +14,7 @@ nlp.add_pipe("span_marker",
14
 
15
  def get_html(html: str):
16
  """Convert HTML so it can be rendered."""
17
- WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem; margin-bottom: 2.5rem">{}</div>"""
18
  # Newlines seem to mess with the rendering
19
  html = html.replace("\n", " ")
20
  style = "<style>mark.entity { display: inline-block }</style>"
@@ -26,7 +26,7 @@ def page_init():
26
  st.header("Named Entity Recognition Demo")
27
 
28
 
29
- @st.cache
30
  def get_html_from_server(text):
31
  base_url = "https://ne-api.iahlt.org/api/hebrew/ner/?text={}"
32
 
@@ -50,17 +50,18 @@ def get_html_from_server(text):
50
 
51
  def render_entities(text):
52
  entities = get_entities(text)
53
- html = displacy.render(entities, style="ent", manual=True)
54
- return html
 
 
 
55
 
56
- return render_entities(text)
57
 
58
 
59
  if __name__ == '__main__':
60
  page_init()
61
 
62
- displacy_options = {}
63
-
64
  sample_text = "讬讜\"专 讜注讚转 讛谞讜注专 谞转谉 住诇讜讘讟讬拽 讗诪专 砖讛砖讞拽谞讬诐 砖诇 讗谞讞谞讜 诇讗 诪砖转诇讘讬诐 讘讗讬专讜驻讛."
65
 
66
  text = st.text_area("Text", sample_text, height=200, max_chars=1000)
@@ -68,8 +69,9 @@ if __name__ == '__main__':
68
  style = """
69
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=David+Libre">
70
  <style>
71
- textarea {
72
- font-size: 16px;
 
73
  font-family: 'David+Libre';
74
  direction: rtl;
75
  }
@@ -78,6 +80,8 @@ if __name__ == '__main__':
78
  font-family: 'David+Libre';
79
  direction: rtl;
80
  }
 
 
81
  </style>
82
  """
83
  st.write(style, unsafe_allow_html=True)
@@ -87,7 +91,7 @@ if __name__ == '__main__':
87
  html = displacy.render(
88
  doc,
89
  style="ent",
90
- options=displacy_options,
91
  manual=False,
92
  )
93
 
@@ -96,11 +100,13 @@ if __name__ == '__main__':
96
 
97
  html = f"""
98
  <div style="display: flex; flex-direction: row; justify-content: space-between; direction: rtl">
99
- <div style="width: 50%">
100
  <h3>Nemo model results</h3>
101
  {nemo_html}
102
  </div>
103
- <div style="width: 50%">
 
 
104
  <h3>IAHLT results</h3>
105
  {iahlt_html}
106
  </div>
 
14
 
15
  def get_html(html: str):
16
  """Convert HTML so it can be rendered."""
17
+ WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem; margin-bottom: 2.5rem"; direction: rtl; >{}</div>"""
18
  # Newlines seem to mess with the rendering
19
  html = html.replace("\n", " ")
20
  style = "<style>mark.entity { display: inline-block }</style>"
 
26
  st.header("Named Entity Recognition Demo")
27
 
28
 
29
+ @st.cache_data
30
  def get_html_from_server(text):
31
  base_url = "https://ne-api.iahlt.org/api/hebrew/ner/?text={}"
32
 
 
50
 
51
  def render_entities(text):
52
  entities = get_entities(text)
53
+ html = displacy.render(entities,
54
+ style="ent",
55
+ options={"direction": "rtl"},
56
+ manual=True)
57
+ return html.replace("ltr", "rtl")
58
 
59
+ return get_html(render_entities(text))
60
 
61
 
62
  if __name__ == '__main__':
63
  page_init()
64
 
 
 
65
  sample_text = "讬讜\"专 讜注讚转 讛谞讜注专 谞转谉 住诇讜讘讟讬拽 讗诪专 砖讛砖讞拽谞讬诐 砖诇 讗谞讞谞讜 诇讗 诪砖转诇讘讬诐 讘讗讬专讜驻讛."
66
 
67
  text = st.text_area("Text", sample_text, height=200, max_chars=1000)
 
69
  style = """
70
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=David+Libre">
71
  <style>
72
+ .stTextArea textarea {
73
+ font-size: 20px;
74
+ font-color: black;
75
  font-family: 'David+Libre';
76
  direction: rtl;
77
  }
 
80
  font-family: 'David+Libre';
81
  direction: rtl;
82
  }
83
+ #MainMenu {visibility: hidden;}
84
+ footer {visibility: hidden;}
85
  </style>
86
  """
87
  st.write(style, unsafe_allow_html=True)
 
91
  html = displacy.render(
92
  doc,
93
  style="ent",
94
+ options={"direction": "rtl"},
95
  manual=False,
96
  )
97
 
 
100
 
101
  html = f"""
102
  <div style="display: flex; flex-direction: row; justify-content: space-between; direction: rtl">
103
+ <div>
104
  <h3>Nemo model results</h3>
105
  {nemo_html}
106
  </div>
107
+ </div>
108
+ <div style="display: flex; flex-direction: row; justify-content: space-between; direction: rtl">
109
+ <div>
110
  <h3>IAHLT results</h3>
111
  {iahlt_html}
112
  </div>