wannaphong commited on
Commit
eb75c2d
1 Parent(s): 0024ab7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -13,13 +13,14 @@ default = "แกว่าเราเข้มแข็งมากพอที
13
  def corefer(text):
14
  preds = model.predict(texts=[text])
15
  clusters = preds[0].get_clusters(as_strings=False)
16
- doc = nlp(text)
17
- doc.spans["sc"] = []
18
- colors = {"Cluster {}".format(i):'#%06X' % randint(0, 0xFFFFFF) for i in range(len(clusters))}
19
- for i, cluster in enumerate(clusters):
20
- for sp in cluster:
21
- doc.spans["sc"] += [doc.char_span(sp[0], sp[1], "Cluster {}".format(i))]
22
- return displacy.render(doc, style="span", options= {"colors":colors }, page=True )
 
23
 
24
 
25
  iface = gr.Interface(fn=corefer,
 
13
  def corefer(text):
14
  preds = model.predict(texts=[text])
15
  clusters = preds[0].get_clusters(as_strings=False)
16
+ title=None
17
+ dic_ents = {"text":text,"ents":[],"title":title}
18
+ _tag=[str(i) for i in list(range(len(clusters)))]
19
+ for i,tag in enumerate(tags):
20
+ for s,e in tag:
21
+ dic_ents["ents"].append({"start": s, "end": e, "label": _tag[i]})
22
+ colors={i:"#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in _tag} # thank https://stackoverflow.com/a/50218895
23
+ return displacy.render(dic_ents, manual=True, style="ent",options=colors)
24
 
25
 
26
  iface = gr.Interface(fn=corefer,