Spaces:
Sleeping
Sleeping
File size: 1,134 Bytes
04623a7 666b71b 04623a7 1a76b03 666b71b abe7365 7d20c67 7026526 7d20c67 7026526 7d20c67 1a76b03 7026526 1084d87 7d20c67 666b71b 1084d87 7d20c67 666b71b 7026526 7d20c67 666b71b 7d20c67 1084d87 7d20c67 |
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 35 36 37 |
import gensim
from gensim.models import Word2Vec
import gradio as gr
# Load your trained Word2Vec model
model = Word2Vec.load("word2vecsg2.model")
def recommend_ingredients(*ingredients):
# Filter out any None values from the ingredients
ingredients = [i for i in ingredients if i]
# Get most similar ingredients
similar_ingredients = model.wv.most_similar(positive=ingredients, topn=8)
# Format the output
output = "\n".join([f"{ingredient}: %{round(similarity*100, 2)}" for ingredient, similarity in similar_ingredients])
return output
# Get the vocabulary of the model and sort it alphabetically
vocab = sorted(model.wv.index_to_key)
# Allow user to select multiple ingredients
ingredient_selections = [gr.inputs.Dropdown(choices=vocab, label=f"Ingredients {i+1}") for i in range(6)]
# Create the interface
iface = gr.Interface(
fn=recommend_ingredients,
inputs=ingredient_selections,
outputs="text",
title="Ingredient Recommender",
description="Select up to 6 ingredients to get recommendations for similar ingredients.",
layout="vertical"
)
iface.launch()
|