enpaiva/FastCoref_LingMess
0
1import gradio as gr2import spacy3from spacy import displacy4from spacy.tokens import Span5from random import randint6from fastcoref import LingMessCoref7 8model = LingMessCoref()9nlp = spacy.blank("en")10 11default = "Lionel Messi has won a record seven Ballon d'Or awards. He signed for Paris Saint-Germain in August 2021. “I would like to thank my family” said the Argentinian footballer. Messi holds the records for most goals in La Liga. Paris Saint-Germain hopes he will do the same in Ligue 1."12 13def 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 25iface = gr.Interface(fn=corefer, 26 inputs=gr.Textbox(label="Enter Text To Corefer with FastCoref", lines=2, value=default), 27 outputs="html")28iface.launch()