File size: 1,018 Bytes
8ec8cd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea9342f
8ec8cd1
 
 
 
 
d98086a
ea9342f
 
 
8ec8cd1
 
 
 
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
27
28
29
30
31
32
33
34
import gradio as gr
import spacy 
from spacy import displacy
import pandas as pd 

df = pd.read_json("cliff_gradio.jsonl", orient="index")
colors = {"ext": "#aa9cfc", "int": "#ff6961", "wor": "#7aecec"}
options = {"colors": colors}

nlp = spacy.blank("en")

def viz(topic_id):
    row = df.loc[topic_id]
    summary = row["summary"]    
    labels = row["labels"]
    score = row["score"]
    ex = [{"text": summary,
       "ents": [{"start": token.idx, "end": token.idx + token.__len__() + 1, "label": label[:3]} for token, label in zip(nlp(summary), labels) if label != "correct"],
       "title": None}]
    return row["article"], displacy.render(ex, style="ent", manual=True, options=options), score


    

demo = gr.Interface(fn=viz,
                    inputs=[gr.Dropdown(df.index.tolist(), label="Select Topic Id")],
                    outputs=[gr.Text(label="Source article"), 
                             gr.HTML(label="summary"), 
                             gr.Number(label="score")])



demo.launch()