-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
124 lines (115 loc) · 4.07 KB
/
app.py
File metadata and controls
124 lines (115 loc) · 4.07 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from flask import Flask, render_template, jsonify, request
import random
app = Flask(__name__)
# Mood-specific recipe data
mood_data = {
"happy": {
"addons": [
"with a Sunny Lemon Dressing",
"Sprinkled with Joyful Confetti",
"Drenched in Smiles Sauce"
],
"ingredients": [
"2 cups of laughter-infused sugar",
"1 teaspoon of sunny zest",
"a handful of rainbow sprinkles",
"3 giggles of whipped cream",
"a splash of sparkling happiness"
],
"steps": [
"Mix with bursts of laughter.",
"Dance while whisking until joyous.",
"Sunbathe dough in warm smiles.",
"Serve with a grin wider than the plate."
],
"image": "/static/images/happy.jpg"
},
"fucked_up": {
"addons": [
"with a Hint of Pure Chaos",
"Served in an Upside-Down Plate",
"Exploding with Anarchy Sauce"
],
"ingredients": [
"a fistful of unidentified crumbs",
"3 tablespoons of pure confusion",
"a splash of questionable liquid",
"half of something you found yesterday",
"dust scraped from the toaster"
],
"steps": [
"Throw everything in a bowl and hope for the best.",
"Ignore all known cooking laws.",
"Season aggressively with regret.",
"Serve immediately... or never."
],
"image": "/static/images/fkedup.jpg"
},
"sad": {
"addons": [
"with a Sprinkle of Melancholy",
"Served Under a Grey Sky",
"Resting in a Puddle of Tears"
],
"ingredients": [
"2 cups of salty tears",
"1 teaspoon of gloomy gravy",
"a handful of soggy croutons",
"half-melted ice cream of regret",
"3 drops of cloudy broth"
],
"steps": [
"Sigh deeply before starting.",
"Stir slowly while staring out the window.",
"Season with whispers of lost dreams.",
"Serve with tissues on the side."
],
"image": "/static/images/sad.jpg"
},
"romantic": {
"addons": [
"with a Kiss of Chocolate Affection",
"Served on a Bed of Rose Petals",
"Drizzled in Love Sauce"
],
"ingredients": [
"1 dozen hand-picked love berries",
"2 cups of passion-whipped cream",
"a sprinkle of heart-shaped sugar",
"melted chocolate of eternal devotion",
"a pinch of romantic spice"
],
"steps": [
"Whisper sweet nothings to the ingredients.",
"Mix slowly while gazing into the distance.",
"Garnish with rose petals in the shape of a heart.",
"Serve under candlelight with soulful music."
],
"image": "/static/images/romantic.jpg"
}
}
# Default mood if none selected
default_mood = "happy"
@app.route("/")
def index():
return render_template("index.html")
@app.route("/generate_recipe", methods=["POST"])
def generate_recipe():
data = request.get_json()
food_name = data.get("foodName", "Mystery Dish").strip()
mood = data.get("mood", default_mood).lower()
# Replace spaces or special chars with safe key format
mood_key = mood.replace(" ", "_")
mood_content = mood_data.get(mood_key, mood_data[default_mood])
recipe_name = f"{food_name} {random.choice(mood_content['addons'])}"
ing = random.sample(mood_content["ingredients"], min(4, len(mood_content["ingredients"])))
step = random.sample(mood_content["steps"], min(4, len(mood_content["steps"])))
image_url = mood_content["image"]
return jsonify({
"name": recipe_name,
"ingredients": ing,
"steps": step,
"image": image_url
})
if __name__ == "__main__":
app.run(debug=True)