abdullahzunorain commited on
Commit
747d197
·
verified ·
1 Parent(s): 94b8e94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -11
app.py CHANGED
@@ -1,19 +1,14 @@
1
  import requests
2
  import streamlit as st
3
  import groq
4
- import os
5
-
6
- # Function to get weather data from OpenWeatherMap
7
-
8
- import os
9
-
10
- # Replace with environment variables
11
- openweather_api_key = os.getenv("weather_api_key")
12
- groq_api_key = os.getenv("groq_api_key")
13
 
 
 
 
14
 
 
15
  def get_weather_data(city):
16
- api_key = openweather_api_key # Replace with your OpenWeatherMap API key
17
  url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
18
  try:
19
  response = requests.get(url)
@@ -35,7 +30,7 @@ def parse_weather_data(weather_data):
35
  def get_outfit_suggestion(temperature, description, style, fabric):
36
  # Initialize Groq's API
37
  try:
38
- client = groq.Groq(api_key=groq_api_key) # Replace with your Groq API key
39
 
40
  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."
41
 
@@ -98,3 +93,110 @@ st.markdown(
98
  """,
99
  unsafe_allow_html=True
100
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
 
30
  def get_outfit_suggestion(temperature, description, style, fabric):
31
  # Initialize Groq's API
32
  try:
33
+ client = groq.Groq(api_key=groq_api_key) # Use the secret API key
34
 
35
  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."
36
 
 
93
  """,
94
  unsafe_allow_html=True
95
  )
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ # import requests
104
+ # import streamlit as st
105
+ # import groq
106
+ # import os
107
+
108
+ # # Function to get weather data from OpenWeatherMap
109
+
110
+ # import os
111
+
112
+ # # Replace with environment variables
113
+ # openweather_api_key = os.getenv("weather_api_key")
114
+ # groq_api_key = os.getenv("groq_api_key")
115
+
116
+
117
+ # def get_weather_data(city):
118
+ # api_key = openweather_api_key # Replace with your OpenWeatherMap API key
119
+ # url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
120
+ # try:
121
+ # response = requests.get(url)
122
+ # response.raise_for_status() # Raise an HTTPError if the HTTP request returned an unsuccessful status code
123
+ # return response.json()
124
+ # except requests.exceptions.HTTPError as err:
125
+ # st.error(f"HTTP error occurred: {err}")
126
+ # except Exception as err:
127
+ # st.error(f"An error occurred: {err}")
128
+ # return None
129
+
130
+ # # Function to parse weather data
131
+ # def parse_weather_data(weather_data):
132
+ # temperature = weather_data["main"]["temp"]
133
+ # weather_description = weather_data["weather"][0]["description"]
134
+ # return temperature, weather_description
135
+
136
+ # # Function to get outfit suggestion using Groq's LLaMA model
137
+ # def get_outfit_suggestion(temperature, description, style, fabric):
138
+ # # Initialize Groq's API
139
+ # try:
140
+ # client = groq.Groq(api_key=groq_api_key) # Replace with your Groq API key
141
+
142
+ # 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."
143
+
144
+ # # Use Groq's chat completion to get the text response
145
+ # response = client.chat.completions.create(
146
+ # messages=[{"role": "user", "content": prompt}],
147
+ # model="llama3-8b-8192", # Change to a valid Groq model if necessary
148
+ # )
149
+ # return response.choices[0].message.content.strip()
150
+ # except Exception as e:
151
+ # st.error(f"Error using Groq API: {e}")
152
+ # return None
153
+
154
+ # # Streamlit UI for user input
155
+ # st.title("Weather-Based Outfit Suggestion App")
156
+
157
+ # city = st.text_input("Enter your location:")
158
+
159
+ # # Add style and fabric input options
160
+ # style = st.selectbox("Select your preferred style", ["Casual", "Formal", "Sporty", "Business", "Chic"])
161
+ # fabric = st.selectbox("Select your preferred fabric", ["Cotton", "Linen", "Wool", "Polyester", "Silk", "Leather"])
162
+
163
+ # if city:
164
+ # weather_data = get_weather_data(city)
165
+
166
+ # if weather_data and weather_data["cod"] == 200:
167
+ # temperature, description = parse_weather_data(weather_data)
168
+
169
+ # # Display current weather info
170
+ # st.write(f"Current temperature in {city}: {temperature}°C")
171
+ # st.write(f"Weather: {description}")
172
+
173
+ # # Get outfit suggestion based on user preferences
174
+ # outfit_suggestion = get_outfit_suggestion(temperature, description, style, fabric)
175
+
176
+ # if outfit_suggestion:
177
+ # # Display outfit suggestion
178
+ # st.write("Outfit Suggestion:")
179
+ # st.write(outfit_suggestion)
180
+
181
+ # # Display weather icon
182
+ # icon_code = weather_data["weather"][0]["icon"]
183
+ # icon_url = f"http://openweathermap.org/img/wn/{icon_code}.png"
184
+ # st.image(icon_url)
185
+ # else:
186
+ # st.write("Could not retrieve weather data. Please check the location.")
187
+
188
+ # # Optional: Add CSS for styling
189
+ # st.markdown(
190
+ # """
191
+ # <style>
192
+ # .reportview-container {
193
+ # background: #f5f5f5;
194
+ # }
195
+ # .stButton>button {
196
+ # background-color: #ff5733;
197
+ # color: white;
198
+ # }
199
+ # </style>
200
+ # """,
201
+ # unsafe_allow_html=True
202
+ # )