File size: 968 Bytes
008231d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
import spacy
from spacy import displacy
from spacy.tokens import Span
from random import randint
from fastcoref import LingMessCoref

model = LingMessCoref()
nlp = spacy.blank("en")

def corefer(text):
    preds = model.predict(texts=[text])
    clusters = preds[0].get_clusters(as_strings=False)
    doc = nlp(text)
    doc.spans["sc"] = []
    colors = {"Cluster {}".format(i):'#%06X' % randint(0, 0xFFFFFF) for i in range(len(clusters))}
    for i, cluster in enumerate(clusters):
      for sp in cluster:
        doc.spans["sc"] += [doc.char_span(sp[0], sp[1], "Cluster {}".format(i))]
    return displacy.render(doc, style="span", options= {"colors":colors }, page=True )


iface = gr.Interface(fn=corefer, 
                     inputs=gr.Textbox(label="Enter Text To Corefer with FastCoref", lines=2, value="We are so happy to see you using our coref package. This package is very fast!"), 
                     outputs="html")
iface.launch()