Spaces:
Sleeping
Sleeping
import gensim | |
from gensim.models import Word2Vec | |
import gradio as gr | |
# Prepare and clean your data | |
# recipes is a list of lists of ingredients. Each list represents a recipe. | |
# For simplicity, let's assume you have already cleaned your data and it's stored in a variable called recipes. | |
# Train Word2Vec Model | |
model = Word2Vec.load("word2vecsg2.model") | |
def recommend_ingredients(ingredients): | |
similar_ingredients = [] | |
for ingredient in ingredients: | |
if ingredient in model.wv.key_to_index: | |
top_similar = model.wv.most_similar(ingredient, topn=5) | |
for ing, similarity in top_similar: | |
similar_ingredients.append((ing, round(similarity, 2))) | |
return similar_ingredients | |
# Create Gradio Interface | |
def gradio_interface(ingredients): | |
ingredients = ingredients.split(',') | |
recommendations = recommend_ingredients(ingredients) | |
formatted_recommendations = [f'{ing} ({similarity})' for ing, similarity in recommendations] | |
return formatted_recommendations | |
iface = gr.Interface(fn=gradio_interface, | |
inputs="text", | |
outputs="text", | |
examples=[["onion,garlic,tomato"], ["beef,chicken"], ["milk,cheese"]]) | |
iface.launch() | |