egecandrsn commited on
Commit
04623a7
1 Parent(s): b923801

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gensim
2
+ from gensim.models import Word2Vec
3
+ import gradio as gr
4
+
5
+ # Prepare and clean your data
6
+ # recipes is a list of lists of ingredients. Each list represents a recipe.
7
+ # For simplicity, let's assume you have already cleaned your data and it's stored in a variable called recipes.
8
+
9
+ # Train Word2Vec Model
10
+ model = Word2Vec.load("word2vecsg2.model")
11
+
12
+ def recommend_ingredients(ingredients):
13
+ similar_ingredients = []
14
+ for ingredient in ingredients:
15
+ if ingredient in model.wv.key_to_index:
16
+ top_similar = model.wv.most_similar(ingredient, topn=5)
17
+ for ing, similarity in top_similar:
18
+ similar_ingredients.append((ing, round(similarity, 2)))
19
+ return similar_ingredients
20
+
21
+ # Create Gradio Interface
22
+ def gradio_interface(ingredients):
23
+ ingredients = ingredients.split(',')
24
+ recommendations = recommend_ingredients(ingredients)
25
+ formatted_recommendations = [f'{ing} ({similarity})' for ing, similarity in recommendations]
26
+ return formatted_recommendations
27
+
28
+ iface = gr.Interface(fn=gradio_interface,
29
+ inputs="text",
30
+ outputs="text",
31
+ examples=[["onion,garlic,tomato"], ["beef,chicken"], ["milk,cheese"]])
32
+
33
+ iface.launch()