egecandrsn commited on
Commit
7026526
1 Parent(s): a29be59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -10,15 +10,15 @@ def recommend_ingredients(*ingredients):
10
  ingredients = [i for i in ingredients if i]
11
 
12
  # Get most similar ingredients
13
- similar_ingredients = model.wv.most_similar(positive=ingredients, topn=5)
14
 
15
  # Format the output
16
- output = {ingredient: round(similarity, 2) for ingredient, similarity in similar_ingredients}
17
 
18
  return output
19
 
20
- # Get the vocabulary of the model
21
- vocab = model.wv.index_to_key
22
 
23
  # Allow user to select multiple ingredients
24
  ingredient_selections = [gr.inputs.Dropdown(choices=vocab, label=f"Ingredients {i+1}") for i in range(6)]
@@ -27,7 +27,7 @@ ingredient_selections = [gr.inputs.Dropdown(choices=vocab, label=f"Ingredients {
27
  iface = gr.Interface(
28
  fn=recommend_ingredients,
29
  inputs=ingredient_selections,
30
- outputs="json",
31
  title="Ingredient Recommender",
32
  description="Select up to 6 ingredients to get recommendations for similar ingredients.",
33
  layout="vertical"
 
10
  ingredients = [i for i in ingredients if i]
11
 
12
  # Get most similar ingredients
13
+ similar_ingredients = model.wv.most_similar(positive=ingredients, topn=8)
14
 
15
  # Format the output
16
+ output = "\n".join([f"{ingredient}: %{round(similarity*100, 2)}" for ingredient, similarity in similar_ingredients])
17
 
18
  return output
19
 
20
+ # Get the vocabulary of the model and sort it alphabetically
21
+ vocab = sorted(model.wv.index_to_key)
22
 
23
  # Allow user to select multiple ingredients
24
  ingredient_selections = [gr.inputs.Dropdown(choices=vocab, label=f"Ingredients {i+1}") for i in range(6)]
 
27
  iface = gr.Interface(
28
  fn=recommend_ingredients,
29
  inputs=ingredient_selections,
30
+ outputs="text",
31
  title="Ingredient Recommender",
32
  description="Select up to 6 ingredients to get recommendations for similar ingredients.",
33
  layout="vertical"