abdullahzunorain commited on
Commit
6b1e6df
1 Parent(s): 210041d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +238 -170
app.py CHANGED
@@ -1,3 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import requests
2
  import streamlit as st
3
  import groq
@@ -50,9 +234,9 @@ def get_outfit_suggestion(temperature, description, style, fabric, weather_categ
50
  try:
51
  client = groq.Groq(api_key=groq_api_key) # Use the secret API key
52
 
53
- # Adjust the prompt based on the weather category and custom style
54
  prompt = f"The current weather is {description} with a temperature of {temperature}°C. The weather category is {weather_category}. Suggest an outfit. The user prefers a {style} style and {fabric} fabric."
55
-
56
  # Use Groq's chat completion to get the text response
57
  response = client.chat.completions.create(
58
  messages=[{"role": "user", "content": prompt}],
@@ -67,8 +251,7 @@ def get_outfit_suggestion(temperature, description, style, fabric, weather_categ
67
  st.set_page_config(page_title="Weather-Based Outfit Suggestion", page_icon="🌤️", layout="wide")
68
 
69
  # Custom styles
70
- st.markdown("""
71
- <style>
72
  .reportview-container {
73
  background: linear-gradient(135deg, #ffcc00, #ff7b00);
74
  }
@@ -106,179 +289,64 @@ st.markdown("""
106
  font-family: "Arial", sans-serif;
107
  margin-top: 30px;
108
  }
109
- </style>
110
- """, unsafe_allow_html=True)
 
 
 
 
 
111
 
 
112
  st.title("🌤️ Weather-Based Outfit Suggestion App")
113
 
114
- # User input
115
- city = st.text_input("Enter your location:", placeholder="E.g. Peshawar")
116
-
117
- # Gender selection
118
- gender = st.selectbox("Select your gender", ["Male", "Female", "Other"])
119
-
120
- # Custom style input
121
- custom_style = st.text_input("Enter your personalized style (optional)", placeholder="E.g. Vintage, Sporty")
122
-
123
- # If no custom style is provided, default to the selected style
124
- style = custom_style if custom_style else st.selectbox("Select your preferred style", ["Casual", "Formal", "Sporty", "Business", "Chic"])
125
 
126
- # Fabric preference
127
- fabric = st.selectbox("Select your preferred fabric", ["Cotton", "Linen", "Wool", "Polyester", "Silk", "Leather"])
 
 
 
 
128
 
129
- if city:
130
- weather_data = get_weather_data(city)
131
-
132
- if weather_data and weather_data["cod"] == 200:
133
- temperature, description = parse_weather_data(weather_data)
134
- # Categorize the weather
135
- weather_category, weather_icon = categorize_weather(description)
136
-
137
- # Display current weather info
138
- st.write(f"Current temperature in {city}: {temperature}°C")
139
- st.write(f"Weather: {description} {weather_icon}")
140
- st.write(f"Weather Category: {weather_category} {weather_icon}")
141
 
142
- # Get outfit suggestion based on user preferences
143
- outfit_suggestion, weather_icon = get_outfit_suggestion(temperature, description, style, fabric, weather_category, weather_icon)
144
-
145
- if outfit_suggestion:
146
- # Display outfit suggestion
147
- st.markdown(f"### 🌟 Outfit Suggestion 🌟")
148
- st.write(outfit_suggestion)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
- # Additional section for Health and Comfort Tips
151
- st.markdown(f"### 🌿 Health & Comfort Tips 🌿")
152
- st.write(f"Given the {weather_category} weather, it's important to take care of your health:")
153
- st.write("- **Breathing**: A face mask or scarf covering your nose and mouth can help protect you from smoke inhalation.")
154
- st.write("- **Hydration**: Keep a water bottle with you, as smoke can dehydrate your body.")
155
- st.write("- **Rest**: Try to avoid strenuous activity outdoors and take breaks if you're feeling fatigued.")
156
- st.write("- **Eyes**: If you're feeling irritated, use eye drops to soothe any discomfort caused by smoke.")
157
-
158
- # Display weather icon
159
- icon_code = weather_data["weather"][0]["icon"]
160
- icon_url = f"http://openweathermap.org/img/wn/{icon_code}.png"
161
- st.image(icon_url)
162
- else:
163
- st.write("Could not retrieve weather data. Please check the location.")
164
-
165
- # Optional: Add CSS for styling
166
- st.markdown(
167
- """
168
- <style>
169
- .stButton>button {
170
- background-color: #ff5733;
171
- color: white;
172
- }
173
- </style>
174
- """,
175
- unsafe_allow_html=True
176
- )
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
- # import requests
187
- # import streamlit as st
188
- # import groq
189
-
190
- # # Access API keys from Streamlit secrets
191
- # openweather_api_key = st.secrets["weather_api_key"]
192
- # groq_api_key = st.secrets["groq_api_key"]
193
-
194
- # # Function to get weather data from OpenWeatherMap
195
- # def get_weather_data(city):
196
- # api_key = openweather_api_key # Use the secret API key
197
- # url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
198
- # try:
199
- # response = requests.get(url)
200
- # response.raise_for_status() # Raise an HTTPError if the HTTP request returned an unsuccessful status code
201
- # return response.json()
202
- # except requests.exceptions.HTTPError as err:
203
- # st.error(f"HTTP error occurred: {err}")
204
- # except Exception as err:
205
- # st.error(f"An error occurred: {err}")
206
- # return None
207
-
208
- # # Function to parse weather data
209
- # def parse_weather_data(weather_data):
210
- # temperature = weather_data["main"]["temp"]
211
- # weather_description = weather_data["weather"][0]["description"]
212
- # return temperature, weather_description
213
-
214
- # # Function to get outfit suggestion using Groq's LLaMA model
215
- # def get_outfit_suggestion(temperature, description, style, fabric):
216
- # # Initialize Groq's API
217
- # try:
218
- # client = groq.Groq(api_key=groq_api_key) # Use the secret API key
219
-
220
- # prompt = f"The current weather is {description} with a temperature of {temperature}°C. Suggest an outfit. The user prefers a {style} style and {fabric} fabric."
221
-
222
- # # Use Groq's chat completion to get the text response
223
- # response = client.chat.completions.create(
224
- # messages=[{"role": "user", "content": prompt}],
225
- # model="llama3-8b-8192", # Change to a valid Groq model if necessary
226
- # )
227
- # return response.choices[0].message.content.strip()
228
- # except Exception as e:
229
- # st.error(f"Error using Groq API: {e}")
230
- # return None
231
-
232
- # # Streamlit UI for user input
233
- # st.title("Weather-Based Outfit Suggestion App")
234
-
235
- # city = st.text_input("Enter your location:")
236
-
237
- # # Add style and fabric input options
238
- # style = st.selectbox("Select your preferred style", ["Casual", "Formal", "Sporty", "Business", "Chic"])
239
- # fabric = st.selectbox("Select your preferred fabric", ["Cotton", "Linen", "Wool", "Polyester", "Silk", "Leather"])
240
-
241
- # if city:
242
- # weather_data = get_weather_data(city)
243
-
244
- # if weather_data and weather_data["cod"] == 200:
245
- # temperature, description = parse_weather_data(weather_data)
246
-
247
- # # Display current weather info
248
- # st.write(f"Current temperature in {city}: {temperature}°C")
249
- # st.write(f"Weather: {description}")
250
-
251
- # # Get outfit suggestion based on user preferences
252
- # outfit_suggestion = get_outfit_suggestion(temperature, description, style, fabric)
253
-
254
- # if outfit_suggestion:
255
- # # Display outfit suggestion
256
- # st.write("Outfit Suggestion:")
257
- # st.write(outfit_suggestion)
258
-
259
- # # Display weather icon
260
- # icon_code = weather_data["weather"][0]["icon"]
261
- # icon_url = f"http://openweathermap.org/img/wn/{icon_code}.png"
262
- # st.image(icon_url)
263
- # else:
264
- # st.write("Could not retrieve weather data. Please check the location.")
265
-
266
- # # Optional: Add CSS for styling
267
- # st.markdown(
268
- # """
269
- # <style>
270
- # .reportview-container {
271
- # background: #f5f5f5;
272
- # }
273
- # .stButton>button {
274
- # background-color: #ff5733;
275
- # color: white;
276
- # }
277
- # </style>
278
- # """,
279
- # unsafe_allow_html=True
280
- # )
281
-
282
 
283
 
284
  # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
1
+ # import requests
2
+ # import streamlit as st
3
+ # import groq
4
+
5
+ # # Access API keys from Streamlit secrets
6
+ # openweather_api_key = st.secrets["weather_api_key"]
7
+ # groq_api_key = st.secrets["groq_api_key"]
8
+
9
+ # # Function to get weather data from OpenWeatherMap
10
+ # def get_weather_data(city):
11
+ # api_key = openweather_api_key # Use the secret API key
12
+ # url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
13
+ # try:
14
+ # response = requests.get(url)
15
+ # response.raise_for_status() # Raise an HTTPError if the HTTP request returned an unsuccessful status code
16
+ # return response.json()
17
+ # except requests.exceptions.HTTPError as err:
18
+ # st.error(f"HTTP error occurred: {err}")
19
+ # except Exception as err:
20
+ # st.error(f"An error occurred: {err}")
21
+ # return None
22
+
23
+ # # Function to parse weather data and categorize weather
24
+ # def parse_weather_data(weather_data):
25
+ # temperature = weather_data["main"]["temp"]
26
+ # weather_description = weather_data["weather"][0]["description"]
27
+ # return temperature, weather_description
28
+
29
+ # # Categorizing weather conditions
30
+ # def categorize_weather(description):
31
+ # description = description.lower()
32
+ # if "clear" in description or "sun" in description:
33
+ # return "Sunny", "☀️"
34
+ # elif "rain" in description or "drizzle" in description or "shower" in description:
35
+ # return "Rainy", "🌧️"
36
+ # elif "snow" in description or "sleet" in description:
37
+ # return "Cold", "❄️"
38
+ # elif "cloud" in description:
39
+ # return "Cloudy", "☁️"
40
+ # elif "wind" in description:
41
+ # return "Windy", "💨"
42
+ # elif "smoke" in description or "haze" in description:
43
+ # return "Smoky", "🌫️"
44
+ # else:
45
+ # return "Uncategorized", "🔍"
46
+
47
+ # # Function to get outfit suggestion using Groq's LLaMA model
48
+ # def get_outfit_suggestion(temperature, description, style, fabric, weather_category, weather_icon):
49
+ # # Initialize Groq's API
50
+ # try:
51
+ # client = groq.Groq(api_key=groq_api_key) # Use the secret API key
52
+
53
+ # # Adjust the prompt based on the weather category and custom style
54
+ # prompt = f"The current weather is {description} with a temperature of {temperature}°C. The weather category is {weather_category}. Suggest an outfit. The user prefers a {style} style and {fabric} fabric."
55
+
56
+ # # Use Groq's chat completion to get the text response
57
+ # response = client.chat.completions.create(
58
+ # messages=[{"role": "user", "content": prompt}],
59
+ # model="llama3-8b-8192", # Change to a valid Groq model if necessary
60
+ # )
61
+ # return response.choices[0].message.content.strip(), weather_icon
62
+ # except Exception as e:
63
+ # st.error(f"Error using Groq API: {e}")
64
+ # return None, None
65
+
66
+ # # Streamlit UI for user input
67
+ # st.set_page_config(page_title="Weather-Based Outfit Suggestion", page_icon="🌤️", layout="wide")
68
+
69
+ # # Custom styles
70
+ # st.markdown("""
71
+ # <style>
72
+ # .reportview-container {
73
+ # background: linear-gradient(135deg, #ffcc00, #ff7b00);
74
+ # }
75
+ # .stButton>button {
76
+ # background-color: #ff5733;
77
+ # color: white;
78
+ # font-size: 18px;
79
+ # border-radius: 10px;
80
+ # padding: 10px;
81
+ # }
82
+ # .stTextInput input {
83
+ # font-size: 16px;
84
+ # padding: 10px;
85
+ # border-radius: 10px;
86
+ # }
87
+ # .stSelectbox select {
88
+ # font-size: 16px;
89
+ # padding: 10px;
90
+ # border-radius: 10px;
91
+ # }
92
+ # .stWrite, .stImage {
93
+ # font-family: "Arial", sans-serif;
94
+ # font-size: 18px;
95
+ # color: #333;
96
+ # }
97
+ # .weather-header {
98
+ # text-align: center;
99
+ # font-size: 36px;
100
+ # color: #ffffff;
101
+ # font-family: "Arial", sans-serif;
102
+ # }
103
+ # .outfit-header {
104
+ # font-size: 24px;
105
+ # color: #444;
106
+ # font-family: "Arial", sans-serif;
107
+ # margin-top: 30px;
108
+ # }
109
+ # </style>
110
+ # """, unsafe_allow_html=True)
111
+
112
+ # st.title("🌤️ Weather-Based Outfit Suggestion App")
113
+
114
+ # # User input
115
+ # city = st.text_input("Enter your location:", placeholder="E.g. Peshawar")
116
+
117
+ # # Gender selection
118
+ # gender = st.selectbox("Select your gender", ["Male", "Female", "Other"])
119
+
120
+ # # Custom style input
121
+ # custom_style = st.text_input("Enter your personalized style (optional)", placeholder="E.g. Vintage, Sporty")
122
+
123
+ # # If no custom style is provided, default to the selected style
124
+ # style = custom_style if custom_style else st.selectbox("Select your preferred style", ["Casual", "Formal", "Sporty", "Business", "Chic"])
125
+
126
+ # # Fabric preference
127
+ # fabric = st.selectbox("Select your preferred fabric", ["Cotton", "Linen", "Wool", "Polyester", "Silk", "Leather"])
128
+
129
+ # if city:
130
+ # weather_data = get_weather_data(city)
131
+
132
+ # if weather_data and weather_data["cod"] == 200:
133
+ # temperature, description = parse_weather_data(weather_data)
134
+ # # Categorize the weather
135
+ # weather_category, weather_icon = categorize_weather(description)
136
+
137
+ # # Display current weather info
138
+ # st.write(f"Current temperature in {city}: {temperature}°C")
139
+ # st.write(f"Weather: {description} {weather_icon}")
140
+ # st.write(f"Weather Category: {weather_category} {weather_icon}")
141
+
142
+ # # Get outfit suggestion based on user preferences
143
+ # outfit_suggestion, weather_icon = get_outfit_suggestion(temperature, description, style, fabric, weather_category, weather_icon)
144
+
145
+ # if outfit_suggestion:
146
+ # # Display outfit suggestion
147
+ # st.markdown(f"### 🌟 Outfit Suggestion 🌟")
148
+ # st.write(outfit_suggestion)
149
+
150
+ # # Additional section for Health and Comfort Tips
151
+ # st.markdown(f"### 🌿 Health & Comfort Tips 🌿")
152
+ # st.write(f"Given the {weather_category} weather, it's important to take care of your health:")
153
+ # st.write("- **Breathing**: A face mask or scarf covering your nose and mouth can help protect you from smoke inhalation.")
154
+ # st.write("- **Hydration**: Keep a water bottle with you, as smoke can dehydrate your body.")
155
+ # st.write("- **Rest**: Try to avoid strenuous activity outdoors and take breaks if you're feeling fatigued.")
156
+ # st.write("- **Eyes**: If you're feeling irritated, use eye drops to soothe any discomfort caused by smoke.")
157
+
158
+ # # Display weather icon
159
+ # icon_code = weather_data["weather"][0]["icon"]
160
+ # icon_url = f"http://openweathermap.org/img/wn/{icon_code}.png"
161
+ # st.image(icon_url)
162
+ # else:
163
+ # st.write("Could not retrieve weather data. Please check the location.")
164
+
165
+ # # Optional: Add CSS for styling
166
+ # st.markdown(
167
+ # """
168
+ # <style>
169
+ # .stButton>button {
170
+ # background-color: #ff5733;
171
+ # color: white;
172
+ # }
173
+ # </style>
174
+ # """,
175
+ # unsafe_allow_html=True
176
+ # )
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
  import requests
186
  import streamlit as st
187
  import groq
 
234
  try:
235
  client = groq.Groq(api_key=groq_api_key) # Use the secret API key
236
 
237
+ # Adjust the prompt based on the weather category
238
  prompt = f"The current weather is {description} with a temperature of {temperature}°C. The weather category is {weather_category}. Suggest an outfit. The user prefers a {style} style and {fabric} fabric."
239
+
240
  # Use Groq's chat completion to get the text response
241
  response = client.chat.completions.create(
242
  messages=[{"role": "user", "content": prompt}],
 
251
  st.set_page_config(page_title="Weather-Based Outfit Suggestion", page_icon="🌤️", layout="wide")
252
 
253
  # Custom styles
254
+ st.markdown("""<style>
 
255
  .reportview-container {
256
  background: linear-gradient(135deg, #ffcc00, #ff7b00);
257
  }
 
289
  font-family: "Arial", sans-serif;
290
  margin-top: 30px;
291
  }
292
+ .left-column {
293
+ padding-right: 20px;
294
+ }
295
+ .right-column {
296
+ padding-left: 20px;
297
+ }
298
+ </style>""", unsafe_allow_html=True)
299
 
300
+ # Title and layout for columns
301
  st.title("🌤️ Weather-Based Outfit Suggestion App")
302
 
303
+ # Create two columns: one for the user input and one for displaying results
304
+ col1, col2 = st.columns([1, 2]) # 1: left column (user input), 2: right column (outfit suggestions)
 
 
 
 
 
 
 
 
 
305
 
306
+ # User input in the left column (col1)
307
+ with col1:
308
+ city = st.text_input("Enter your location:", placeholder="E.g. Peshawar")
309
+ gender = st.selectbox("Select your gender", ["Male", "Female"])
310
+ personalized_style = st.text_input("Enter your personalized style (optional)", placeholder="E.g. Peshawari")
311
+ fabric = st.selectbox("Select your preferred fabric", ["Cotton", "Linen", "Wool", "Polyester", "Silk", "Leather"])
312
 
313
+ # Result display in the right column (col2)
314
+ with col2:
315
+ if city:
316
+ weather_data = get_weather_data(city)
 
 
 
 
 
 
 
 
317
 
318
+ if weather_data and weather_data["cod"] == 200:
319
+ temperature, description = parse_weather_data(weather_data)
320
+ # Categorize the weather
321
+ weather_category, weather_icon = categorize_weather(description)
322
+
323
+ # Display current weather info
324
+ st.write(f"Current temperature in {city}: {temperature}°C")
325
+ st.write(f"Weather: {description} {weather_icon}")
326
+ st.write(f"Weather Category: {weather_category} {weather_icon}")
327
+
328
+ # Get outfit suggestion based on user preferences
329
+ outfit_suggestion, weather_icon = get_outfit_suggestion(temperature, description, personalized_style, fabric, weather_category, weather_icon)
330
+
331
+ if outfit_suggestion:
332
+ # Display outfit suggestion
333
+ st.markdown(f"### 🌟 Outfit Suggestion 🌟")
334
+ st.write(outfit_suggestion)
335
+
336
+ # Additional section for Health and Comfort Tips
337
+ st.markdown(f"### 🌿 Health & Comfort Tips 🌿")
338
+ st.write(f"Given the {weather_category} weather, it's important to take care of your health:")
339
+ st.write("- **Breathing**: A face mask or scarf covering your nose and mouth can help protect you from smoke inhalation.")
340
+ st.write("- **Hydration**: Keep a water bottle with you, as smoke can dehydrate your body.")
341
+ st.write("- **Rest**: Try to avoid strenuous activity outdoors and take breaks if you're feeling fatigued.")
342
+ st.write("- **Eyes**: If you're feeling irritated, use eye drops to soothe any discomfort caused by smoke.")
343
 
344
+ # Display weather icon
345
+ icon_code = weather_data["weather"][0]["icon"]
346
+ icon_url = f"http://openweathermap.org/img/wn/{icon_code}.png"
347
+ st.image(icon_url)
348
+ else:
349
+ st.write("Could not retrieve weather data. Please check the location.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
 
352
  # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------