eat / app.py
joheras's picture
Update app.py
bdf20f1
raw
history blame contribute delete
838 Bytes
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)