qanastek commited on
Commit
ec78bff
1 Parent(s): 204126b
Files changed (2) hide show
  1. app.py +5 -14
  2. requirements.txt +1 -2
app.py CHANGED
@@ -12,6 +12,8 @@ checkpoints = [
12
  "qanastek/pos-french",
13
  ]
14
 
 
 
15
  @st.cache(suppress_st_warning=True, allow_output_mutation=True)
16
  def get_model(model_name):
17
  return SequenceTagger.load(model_name) # Load the model
@@ -28,17 +30,7 @@ def getPos(s: Sentence):
28
  def getDictFromPOS(texts, labels):
29
  return [{ "text": t, "label": l } for t, l in zip(texts, labels)]
30
 
31
- def randomColor():
32
- rgb = (random.uniform(0.0,1.0), random.uniform(0.0,1.0), random.uniform(0.0,1.0))
33
- hsl = (random.uniform(0.0,1.0), random.uniform(0.35,1.0), 0.75)
34
- return str(Color(rgb=rgb, hsl=hsl))
35
-
36
- def get_colors(model):
37
- labels = [t.decode("utf-8") for t in model.tag_dictionary.idx2item if t.isupper() and len(t) > 1]
38
- colors = [randomColor() for t in model.tag_dictionary.idx2item if t.isupper() and len(t) > 1]
39
- return dict(zip(labels, colors))
40
-
41
- def getAnnotatedFromPOS(texts, labels, colors):
42
  return [(t,l,colors[l]) for t, l in zip(texts, labels)]
43
 
44
  def main():
@@ -47,8 +39,7 @@ def main():
47
 
48
  checkpoint = st.selectbox("Choose model", checkpoints)
49
  model = get_model(checkpoint)
50
- colors = get_colors(model)
51
-
52
  default_text = "George Washington est allé à Washington"
53
  input_text = st.text_area(
54
  label="Original text",
@@ -71,7 +62,7 @@ def main():
71
  texts, labels = getPos(s)
72
 
73
  st.header("Labels:")
74
- anns = getAnnotatedFromPOS(texts, labels, colors)
75
  annotated_text(*anns)
76
 
77
  st.header("JSON:")
12
  "qanastek/pos-french",
13
  ]
14
 
15
+ colors = {'DET': '#b9d9a6', 'NFP': '#eddc92', 'ADJFP': '#95e9d7', 'AUX': '#e797db', 'VPPMS': '#9ff48b', 'ADV': '#ed92b4', 'PREP': '#decfa1', 'PDEMMS': '#ada7d7', 'NMS': '#85fad8', 'COSUB': '#8ba4f4', 'PINDMS': '#e7a498', 'PPOBJMS': '#e5c79a', 'VERB': '#eb94b6', 'DETFS': '#e698ae', 'NFS': '#d9d1a6', 'YPFOR': '#96e89f', 'VPPFS': '#e698c6', 'PUNCT': '#ddbfa2', 'DETMS': '#f788cd', 'PROPN': '#f19c8d', 'ADJMS': '#8ed5f0', 'PPER3FS': '#c4d8a6', 'ADJFS': '#e39bdc', 'COCO': '#8df1e2', 'NMP': '#d7f787', 'PREL': '#f986f0', 'PPER1S': '#878df8', 'ADJMP': '#83fe80', 'VPPMP': '#a6d8c9', 'DINTMS': '#d9a6cc', 'PPER3MS': '#a1deda', 'PPER3MP': '#8fefe1', 'PREF': '#e3c79b', 'ADJ': '#fb81fe', 'DINTFS': '#d5fe81', 'CHIF': '#8084ff', 'XFAMIL': '#dd80fe', 'PRELFS': '#9ce3e3', 'SYM': '#9fbddf', 'NOUN': '#dea1b5', 'MOTINC': '#93b8ec', 'PINDFS': '#f787a5', 'PPOBJMP': '#dca3d2', 'NUM': '#b2e897', 'PREFP': '#e39cd0', 'PDEMFS': '#d8a7cb', 'VPPFP': '#83d9fb', 'PPER3FP': '#a1ddaa', 'PPOBJFS': '#e9ca95', 'PINDMP': '#e897e3', 'PRON': '#e29dcc', 'PPOBJFP': '#86f9dc', 'PART': '#aa96e8', 'PDEMMP': '#b2d7a8', 'PRELMS': '#e39bde', 'PDEMFP': '#b1e599', 'PRELFP': '#bbe39b', 'INTJ': '#bde996', 'PREFS': '#b39be4', 'PINDFP': '#e2e897', 'PRELMP': '#a5c0da', 'PINTFS': '#ceff80', 'PPER2S': '#d5a2dd', 'VPPRE': '#e78af4', '<START>': '#e6a899', '<STOP>': '#9adde5'}
16
+
17
  @st.cache(suppress_st_warning=True, allow_output_mutation=True)
18
  def get_model(model_name):
19
  return SequenceTagger.load(model_name) # Load the model
30
  def getDictFromPOS(texts, labels):
31
  return [{ "text": t, "label": l } for t, l in zip(texts, labels)]
32
 
33
+ def getAnnotatedFromPOS(texts, labels):
 
 
 
 
 
 
 
 
 
 
34
  return [(t,l,colors[l]) for t, l in zip(texts, labels)]
35
 
36
  def main():
39
 
40
  checkpoint = st.selectbox("Choose model", checkpoints)
41
  model = get_model(checkpoint)
42
+
 
43
  default_text = "George Washington est allé à Washington"
44
  input_text = st.text_area(
45
  label="Original text",
62
  texts, labels = getPos(s)
63
 
64
  st.header("Labels:")
65
+ anns = getAnnotatedFromPOS(texts, labels)
66
  annotated_text(*anns)
67
 
68
  st.header("JSON:")
requirements.txt CHANGED
@@ -1,3 +1,2 @@
1
  flair==0.8.0.post1
2
- st-annotated-text
3
- colour
1
  flair==0.8.0.post1
2
+ st-annotated-text