-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
64 lines (50 loc) · 1.79 KB
/
Copy pathapp.py
File metadata and controls
64 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, jsonify, request, render_template
import requests
import openai
import store
import os
app = Flask(__name__, static_url_path='', static_folder='foodapp/build')
@app.route("/")
def index():
return app.send_static_file('index.html')
@app.route("/login", methods=["POST"])
def indexlogin():
userName = request.args.get("username")
return app.send_static_file('index.html')
@app.route("/login", methods=["GET"])
def Userlogin():
return app.send_static_file('index.html')
@app.route("/recipe", methods=["GET"])
def get_recipe():
ingredient = request.args.get("query")
userName = request.args.get("username")
data = None
if store.checkExistence(ingredient,userName):
data = store.loadFood(ingredient,userName)
else:
api_key = "03ddc246f52b4243ab132773e2452ef2"
number = 100
url = f"https://api.spoonacular.com/recipes/complexSearch?apiKey={api_key}&query={ingredient}&number={number}"
response = requests.get(url)
data = response.json()
store.storeFood(data, ingredient,userName)
data = store.loadFood(ingredient,userName )
return jsonify({'results' : data})
@app.route("/like", methods=["POST"])
def like():
query = request.args.get("query")
id = request.args.get("id")
userName = request.args.get("username")
print(id, userName, flush=True)
return jsonify({'result' : store.addLike(id, userName, query)})
@app.route("/reciperm", methods=["GET"])
def get_recipe2():
ingredient = request.args.get("query")
openai.api_key = ""
data = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "system", "content": "can I have some menu for " + ingredient + "?"}]
)
return jsonify(data)
if __name__ == "__main__":
app.run(debug=True)