Mark7549's picture
fixed bug where n was always 10 in nearest neighbours function
d2c01c1
import gradio as gr
from word2vec import get_cosine_similarity, get_cosine_similarity_one_word, get_nearest_neighbours, load_all_models
def greet(name, name2, name3):
return f"hello {name}!"
with gr.Blocks() as demo:
gr.Markdown("# Welcome to Ancient Greek Word2Vec")
# Tab 1
with gr.Tab("Find nearest neighbours"):
gr.Markdown("## Find nearest neighbours of a word")
iface = gr.Interface(
fn=get_nearest_neighbours,
inputs=[
gr.Textbox(label='Word 1 (required)', placeholder='χρηστήριον'),
gr.Radio(label='Time slice (required)', choices=["archaic_cbow", "classical_cbow", "early_roman_cbow", "hellen_cbow", "late_roman_cbow"]),
gr.Slider(label='Number of neighbours', minimum=1, maximum=50, step=1)
],
outputs=gr.DataFrame(
label="Result",
headers=["Word", "Time slice", "Cosine similarity"],
type="pandas", visible=True, interactive=False
),
submit_btn='Calculate',
)
# Tab 2
with gr.Tab("Cosine similarity"):
gr.Markdown("## Cosine similarity")
gr.Markdown('### Two different words')
iface = gr.Interface(
fn=get_cosine_similarity,
inputs=[
gr.Textbox(label='Word 1', placeholder='χρηστήριον'),
gr.Textbox(label='Word 2', placeholder='λίκνον'),
gr.Radio(label='Time slice', choices=["archaic_cbow", "classical_cbow", "early_roman_cbow", "hellen_cbow", "late_roman_cbow"])
],
outputs=gr.Textbox(label="Result"),
submit_btn='Calculate'
)
gr.Markdown('### One word in different time slices')
iface = gr.Interface(
fn=get_cosine_similarity_one_word,
inputs=[
gr.Textbox(label='Word', placeholder='χρηστήριον'),
gr.Radio(label='Time slice', choices=["archaic_cbow", "classical_cbow", "early_roman_cbow", "hellen_cbow", "late_roman_cbow"]),
gr.Radio(label='Time slice', choices=["archaic_cbow", "classical_cbow", "early_roman_cbow", "hellen_cbow", "late_roman_cbow"])
],
outputs=gr.Textbox(label="Result"),
submit_btn='Calculate'
)
# Tab 3
with gr.Tab("3D graph"):
gr.Markdown("## 3D graph")
# Tab 4
with gr.Tab("Dictionary"):
gr.Markdown("## Dictionary")
if __name__ == "__main__":
demo.launch()