abdullahrehan commited on
Commit
5c5337a
Β·
verified Β·
1 Parent(s): 46b17f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +185 -32
app.py CHANGED
@@ -1,40 +1,193 @@
1
- # Hello
 
2
  import os
3
  import streamlit as st
4
  from groq import Groq
5
 
6
- # Load your GROQ API Key (set this in Hugging Face Secrets)
7
- GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
 
 
 
 
 
 
8
 
 
 
 
 
9
  client = Groq(api_key=GROQ_API_KEY)
10
 
11
- st.set_page_config(page_title="AI Recipe Generator", layout="centered")
12
- st.title("πŸ‘¨β€πŸ³ Smart Recipe Generator")
13
- st.caption("Tell me your ingredients and get 3 recipe options by calories!")
14
-
15
- # Step 1: User input
16
- ingredients = st.text_input("πŸ₯• What ingredients do you have?", placeholder="e.g. chicken, tomato, rice")
17
- preferred_cuisine = st.text_input("🌍 What type of cuisine do you prefer?", placeholder="Optional: Chinese, Asian, Italian...")
18
-
19
- if st.button("🍽️ Generate Recipes") and ingredients.strip():
20
- with st.spinner("Thinking of delicious recipes..."):
21
- prompt = f"""
22
- You are a smart recipe generator AI. The user has these ingredients: {ingredients}.
23
- They prefer this cuisine: {preferred_cuisine if preferred_cuisine else 'any'}.
24
- You must decide what types of dishes can be made and suggest 3 recipes:
25
- 1. One with low calories
26
- 2. One with moderate calories
27
- 3. One with high calories
28
- Give recipe names, steps, and estimated calories.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  """
30
- chat_completion = client.chat.completions.create(
31
- messages=[{"role": "user", "content": prompt}],
32
- model="llama-3.3-70b-versatile"
33
- )
34
-
35
- recipes = chat_completion.choices[0].message.content
36
- st.success("🍳 Recipes Generated!")
37
- st.markdown("### πŸ“‹ Your Recipes")
38
- st.markdown(recipes)
39
- else:
40
- st.info("Please enter the ingredients to generate recipes.")
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
  import os
4
  import streamlit as st
5
  from groq import Groq
6
 
7
+ # ----------------------------
8
+ # CONFIG
9
+ # ----------------------------
10
+ st.set_page_config(
11
+ page_title="Diet Pal",
12
+ page_icon="πŸ₯—",
13
+ layout="centered"
14
+ )
15
 
16
+ # ----------------------------
17
+ # API KEY
18
+ # ----------------------------
19
+ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
20
  client = Groq(api_key=GROQ_API_KEY)
21
 
22
+ # ----------------------------
23
+ # TITLE
24
+ # ----------------------------
25
+ st.title("πŸ₯— Diet Pal")
26
+ st.caption("Your AI Nutrition Assistant | Recipes + Diet Plans")
27
+
28
+ # ----------------------------
29
+ # MAIN MENU
30
+ # ----------------------------
31
+ feature = st.radio(
32
+ "Choose an option:",
33
+ ["🍳 Recipe Generator", "πŸ“‹ Diet Planner"]
34
+ )
35
+
36
+ # ==================================================
37
+ # RECIPE GENERATOR
38
+ # ==================================================
39
+ if feature == "🍳 Recipe Generator":
40
+
41
+ st.markdown("## 🍽️ Smart Recipe Generator")
42
+
43
+ ingredients = st.text_input(
44
+ "πŸ₯• What ingredients do you have?",
45
+ placeholder="e.g. chicken, tomato, rice"
46
+ )
47
+
48
+ cuisine = st.text_input(
49
+ "🌍 What type of cuisine do you prefer?",
50
+ placeholder="Optional: Chinese, Pakistani, Italian..."
51
+ )
52
+
53
+ if st.button("🍳 Generate Recipes"):
54
+
55
+ if ingredients.strip():
56
+
57
+ with st.spinner("Thinking of delicious recipes..."):
58
+
59
+ prompt = f"""
60
+ You are Diet Pal AI.
61
+
62
+ The user has these ingredients:
63
+ {ingredients}
64
+
65
+ Preferred cuisine:
66
+ {cuisine if cuisine else "Any"}
67
+
68
+ Generate 3 recipes:
69
+
70
+ 1. Low calorie recipe
71
+ 2. Moderate calorie recipe
72
+ 3. High calorie recipe
73
+
74
+ For each recipe give:
75
+
76
+ - Recipe Name
77
+ - Estimated Calories
78
+ - Ingredients
79
+ - Steps
80
+ - Protein / Carbs / Fats
81
+ """
82
+
83
+ chat_completion = client.chat.completions.create(
84
+ messages=[
85
+ {"role": "user", "content": prompt}
86
+ ],
87
+ model="llama-3.3-70b-versatile"
88
+ )
89
+
90
+ result = chat_completion.choices[0].message.content
91
+
92
+ st.success("🍳 Recipes Generated!")
93
+ st.markdown("### πŸ“‹ Your Recipes")
94
+ st.markdown(result)
95
+
96
+ else:
97
+ st.warning("Please enter ingredients first.")
98
+
99
+ # ==================================================
100
+ # DIET PLANNER
101
+ # ==================================================
102
+ elif feature == "πŸ“‹ Diet Planner":
103
+
104
+ st.markdown("## πŸ“‹ Personal Diet Planner")
105
+
106
+ goal = st.radio(
107
+ "🎯 What is your goal?",
108
+ ["Lose Weight", "Gain Weight"]
109
+ )
110
+
111
+ age = st.number_input("πŸŽ‚ Age", min_value=10, max_value=100, value=20)
112
+
113
+ weight = st.number_input(
114
+ "βš–οΈ Weight (kg)",
115
+ min_value=20,
116
+ max_value=250,
117
+ value=70
118
+ )
119
+
120
+ height = st.number_input(
121
+ "πŸ“ Height (cm)",
122
+ min_value=100,
123
+ max_value=250,
124
+ value=170
125
+ )
126
+
127
+ gender = st.selectbox(
128
+ "πŸ§‘ Gender",
129
+ ["Male", "Female"]
130
+ )
131
+
132
+ activity = st.selectbox(
133
+ "πŸƒ Activity Level",
134
+ ["Low", "Moderate", "High"]
135
+ )
136
+
137
+ allergies = st.text_input(
138
+ "🚫 Allergies / Foods to Avoid",
139
+ placeholder="e.g. nuts, milk, gluten"
140
+ )
141
+
142
+ meals = st.selectbox(
143
+ "🍽️ Meals per Day",
144
+ [3, 4, 5, 6]
145
+ )
146
+
147
+ if st.button("πŸš€ Generate Diet Plan"):
148
+
149
+ with st.spinner("Creating your custom plan..."):
150
+
151
+ prompt = f"""
152
+ You are Diet Pal AI nutrition expert.
153
+
154
+ Create a personalized one-day diet plan.
155
+
156
+ User Goal: {goal}
157
+ Age: {age}
158
+ Weight: {weight} kg
159
+ Height: {height} cm
160
+ Gender: {gender}
161
+ Activity Level: {activity}
162
+ Allergies: {allergies if allergies else "None"}
163
+ Meals Per Day: {meals}
164
+
165
+ Provide:
166
+
167
+ 1. Recommended Daily Calories
168
+ 2. Breakfast
169
+ 3. Lunch
170
+ 4. Dinner
171
+ 5. Snacks
172
+ 6. Water Intake
173
+ 7. Helpful Tips
174
  """
175
+
176
+ chat_completion = client.chat.completions.create(
177
+ messages=[
178
+ {"role": "user", "content": prompt}
179
+ ],
180
+ model="llama-3.3-70b-versatile"
181
+ )
182
+
183
+ result = chat_completion.choices[0].message.content
184
+
185
+ st.success("πŸ₯— Diet Plan Ready!")
186
+ st.markdown("### πŸ“‹ Your Plan")
187
+ st.markdown(result)
188
+
189
+ # ----------------------------
190
+ # FOOTER
191
+ # ----------------------------
192
+ st.markdown("---")
193
+ st.caption("Powered by Groq + Streamlit πŸš€")