File size: 838 Bytes
39a1800 bdf20f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import gradio as gr
import pandas as pd
names = pd.read_csv('vertices.txt',delimiter=" ",names=["i","name"])
relations = pd.read_csv('arcs.txt',delimiter=" ",names=["source","target","times"])
def get_targets_from_source(source):
return relations[relations.source==source].target.values
def get_index(term):
return names[names.name==term].i.values[0]
def get_target_names(listtargets,top_words):
return [names[names.i==target].name.values[0] for target in listtargets][:top_words]
def get_associations(term,top_words=10):
term = term.upper()
return pd.DataFrame(get_target_names(get_targets_from_source(get_index(term)),top_words),columns=['associations'])
iface = gr.Interface(fn=get_associations, inputs="text", outputs=gr.Dataframe(headers=['associations']),examples=["cat"]).launch(share=False)
|