Spaces:
Runtime error
Runtime error
Commit
·
1e794df
1
Parent(s):
f606d3a
refactor
Browse files
app.py
CHANGED
|
@@ -42,30 +42,10 @@ def get_recipe_data(recipe_url):
|
|
| 42 |
|
| 43 |
return instructions, ingredients, recipe_title
|
| 44 |
|
| 45 |
-
def
|
| 46 |
nlp = spacy.load("en_core_web_sm")
|
| 47 |
|
| 48 |
-
doc = ner(
|
| 49 |
-
|
| 50 |
-
ingredients_list = []
|
| 51 |
-
|
| 52 |
-
for item in doc:
|
| 53 |
-
if item[1] == 'INGREDIENT':
|
| 54 |
-
item_lemma = ' ' .join([tok.lemma_ for tok in nlp(item[0])])
|
| 55 |
-
if item_lemma not in ingredients_list:
|
| 56 |
-
ingredients_list.append(item_lemma)
|
| 57 |
-
|
| 58 |
-
ingredients_out = ""
|
| 59 |
-
|
| 60 |
-
for i in range(len(ingredients_list)):
|
| 61 |
-
ingredients_out += f'{i+1}. {ingredients_list[i]} \n'
|
| 62 |
-
|
| 63 |
-
return ingredients_out
|
| 64 |
-
|
| 65 |
-
def get_instruction_data(instructions):
|
| 66 |
-
nlp = spacy.load("en_core_web_sm")
|
| 67 |
-
|
| 68 |
-
doc = ner(instructions)
|
| 69 |
|
| 70 |
ingredients_list = []
|
| 71 |
|
|
@@ -86,7 +66,13 @@ def final_ingredients(inst_ingredients_list, ingr_ingredients_list):
|
|
| 86 |
instructions_guess = [re.sub(r'[0-9]+', '', item)[2:-1] for item in inst_ingredients_list.split('\n')if len(item) > 3]
|
| 87 |
ingredients_guess = [re.sub(r'[0-9]+', '', item)[2:-1] for item in ingr_ingredients_list.split('\n')if len(item) > 3]
|
| 88 |
|
| 89 |
-
final_guess_list = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
final_guess = ""
|
| 92 |
|
|
@@ -122,8 +108,8 @@ with gr.Blocks() as demo:
|
|
| 122 |
|
| 123 |
|
| 124 |
recipe_btn.click(fn=get_recipe_data, inputs=recipe_link, outputs=[instructions, ingredients, recipe_title])
|
| 125 |
-
ingredient_btn.click(fn=
|
| 126 |
-
ingredient_btn.click(fn=
|
| 127 |
final_btn.click(fn=final_ingredients, inputs=[inst_ingredients_list, ingr_ingredients_list], outputs=[final_ingredients_list])
|
| 128 |
|
| 129 |
demo.launch()
|
|
|
|
| 42 |
|
| 43 |
return instructions, ingredients, recipe_title
|
| 44 |
|
| 45 |
+
def get_data(data):
|
| 46 |
nlp = spacy.load("en_core_web_sm")
|
| 47 |
|
| 48 |
+
doc = ner(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
ingredients_list = []
|
| 51 |
|
|
|
|
| 66 |
instructions_guess = [re.sub(r'[0-9]+', '', item)[2:-1] for item in inst_ingredients_list.split('\n')if len(item) > 3]
|
| 67 |
ingredients_guess = [re.sub(r'[0-9]+', '', item)[2:-1] for item in ingr_ingredients_list.split('\n')if len(item) > 3]
|
| 68 |
|
| 69 |
+
final_guess_list = []
|
| 70 |
+
|
| 71 |
+
for ingr_item in ingredients_guess:
|
| 72 |
+
for inst_item in instructions_guess:
|
| 73 |
+
if inst_item in ingr_item and ingr_item not in final_guess_list:
|
| 74 |
+
final_guess_list.append(ingr_item)
|
| 75 |
+
|
| 76 |
|
| 77 |
final_guess = ""
|
| 78 |
|
|
|
|
| 108 |
|
| 109 |
|
| 110 |
recipe_btn.click(fn=get_recipe_data, inputs=recipe_link, outputs=[instructions, ingredients, recipe_title])
|
| 111 |
+
ingredient_btn.click(fn=get_data, inputs=[ingredients], outputs=[ingr_ingredients_list])
|
| 112 |
+
ingredient_btn.click(fn=get_data, inputs=[instructions], outputs=[inst_ingredients_list])
|
| 113 |
final_btn.click(fn=final_ingredients, inputs=[inst_ingredients_list, ingr_ingredients_list], outputs=[final_ingredients_list])
|
| 114 |
|
| 115 |
demo.launch()
|