imvladikon commited on
Commit
95c0484
1 Parent(s): df409af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -2
app.py CHANGED
@@ -1,3 +1,60 @@
1
- import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- gr.load("models/iahlt/span-marker-xlm-roberta-base-ar").launch()
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ import streamlit as st
4
+ from spacy import displacy
5
+
6
+ import span_marker
7
+ import spacy
8
+ import spacy_udpipe
9
+
10
+
11
+ spacy_udpipe.download("ar")
12
+ nlp = spacy_udpipe.load("ar")
13
+ nlp.add_pipe("span_marker",
14
+ config={"model": "iahlt/span-marker-xlm-roberta-base-ar"})
15
+
16
+ def get_html(html: str):
17
+ """Convert HTML so it can be rendered."""
18
+ WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem; margin-bottom: 2.5rem">{}</div>"""
19
+ # Newlines seem to mess with the rendering
20
+ html = html.replace("\n", " ")
21
+ return WRAPPER.format(html)
22
+
23
+ def page_init():
24
+ st.header("Named Entity Recognition Demo")
25
+
26
+
27
+ if __name__ == '__main__':
28
+ page_init()
29
+
30
+ displacy_options = {}
31
+
32
+ sample_text = "تعلم في جامعة أوكسفورد، جامعة برنستون، جامعة كولومبيا."
33
+
34
+ text = st.text_area("Text", sample_text, height=200, max_chars=1000)
35
+ btn = st.button("Annotate")
36
+ if text and btn:
37
+ doc = nlp(text)
38
+ html = displacy.render(
39
+ doc,
40
+ style="ent",
41
+ options=displacy_options,
42
+ manual=False,
43
+ )
44
+ style = "<style>mark.entity { display: inline-block }</style>"
45
+ st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)
46
+ else:
47
+ st.write("")
48
+
49
+ st.markdown(
50
+ """
51
+ <style>
52
+ textarea {
53
+ direction: rtl;
54
+ }
55
+ </style>
56
+ """,
57
+ unsafe_allow_html=True,
58
+ )
59
+
60