Victoria Slocum commited on
Commit
a6b7b32
·
1 Parent(s): dc2482c

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +81 -0
  3. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .env
2
+ model
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dis import Instruction
2
+ import requests
3
+ from decouple import config
4
+ import gradio as gr
5
+ import spacy
6
+
7
+ # for generating requirements.txt, use:
8
+ # pip install pipreqs
9
+ # pipreqs ./ --force
10
+
11
+ RAPIDAPI_KEY = config('RAPIDAPI_KEY')
12
+
13
+ def get_recipe_data(recipe_url):
14
+ rapid_api_url = "https://mycookbook-io1.p.rapidapi.com/recipes/rapidapi"
15
+
16
+ headers = {
17
+ "content-type": "text/plain",
18
+ "X-RapidAPI-Host": "mycookbook-io1.p.rapidapi.com",
19
+ "X-RapidAPI-Key": RAPIDAPI_KEY
20
+ }
21
+
22
+ response = requests.request("POST", rapid_api_url,
23
+ data=recipe_url, headers=headers).json()
24
+
25
+ instructions_list = response[0]['instructions'][0]['steps']
26
+ ingredients_list = response[0]['ingredients']
27
+ recipe_title = response[0]['name']
28
+
29
+ instructions = ""
30
+ ingredients = ""
31
+
32
+ for i in range(len(instructions_list)):
33
+ instructions += f'{i+1}. {instructions_list[i]} \n'
34
+
35
+ for i in range(len(ingredients_list)):
36
+ ingredients += f'{i+1}. {ingredients_list[i]} \n'
37
+
38
+ return instructions, ingredients, recipe_title
39
+
40
+ def get_ingredient_data(instructions, ingredients):
41
+ nlp = spacy.load("./model")
42
+ doc = nlp(instructions)
43
+
44
+ ingredients_list = []
45
+
46
+ # TODO: add lemmatizer
47
+ for ent in doc.ents:
48
+ if ent not in ingredients_list:
49
+ ingredients_list.append(ent)
50
+
51
+ ingredients = ""
52
+
53
+ for i in range(len(ingredients_list)):
54
+ ingredients += f'{i+1}. {ingredients_list[i]} \n'
55
+
56
+ return ingredients
57
+
58
+ with gr.Blocks() as demo:
59
+ gr.Markdown("# Reciparse Visualizer")
60
+ gr.Markdown("### Powered by spaCy, Prodigy, and Gradio")
61
+ with gr.Box():
62
+ with gr.Column():
63
+ gr.Markdown("## Recipe Info")
64
+ with gr.Row():
65
+ recipe_link = gr.Textbox(label="Recipe link", placeholder="Input your recipe link")
66
+ recipe_title = gr.Textbox(label="Recipe title")
67
+ with gr.Row():
68
+ instructions = gr.Textbox(label="Instructions")
69
+ ingredients = gr.Textbox(label="Ingredients")
70
+ recipe_btn = gr.Button("Get recipe info")
71
+
72
+ with gr.Box():
73
+ with gr.Column():
74
+ gr.Markdown("## Recipe Info")
75
+ ingredient_btn = gr.Button("Get the list of ingredients")
76
+ ingredient_list = gr.Textbox(label="Ingredients in recipe")
77
+
78
+ recipe_btn.click(fn=get_recipe_data, inputs=recipe_link, outputs=[instructions, ingredients, recipe_title])
79
+ ingredient_btn.click(fn=get_ingredient_data, inputs=[instructions, ingredients], outputs=[ingredient_list])
80
+
81
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.0.24
2
+ python-decouple==3.6
3
+ requests==2.28.1
4
+ spacy==3.3.1