Spaces:
Runtime error
Runtime error
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() |