abdullahzunorain
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -26,19 +26,28 @@ def get_weather_data(city):
|
|
26 |
st.error("Could not retrieve weather data. Please check your API key and city name.")
|
27 |
return None
|
28 |
|
29 |
-
# Function to get outfit suggestion from Groq
|
30 |
-
def get_outfit_suggestion(weather_condition):
|
31 |
-
url = "https://api.groq.com/v1/
|
32 |
headers = {
|
33 |
"Authorization": f"Bearer {groq_api_key}",
|
34 |
"Content-Type": "application/json"
|
35 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
payload = {
|
37 |
-
"
|
|
|
38 |
}
|
|
|
39 |
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
40 |
if response.status_code == 200:
|
41 |
-
return response.json().get("
|
42 |
else:
|
43 |
st.error("Could not retrieve outfit suggestions. Please check your Groq API.")
|
44 |
return None
|
@@ -72,6 +81,7 @@ st.markdown("<h1 class='main-header'>Weather-Based Outfit Suggestion App</h1>",
|
|
72 |
|
73 |
# Try auto-detecting location if city is empty
|
74 |
city = st.text_input("Enter your location:", value=get_location_by_ip() or "")
|
|
|
75 |
|
76 |
if city:
|
77 |
weather_data = get_weather_data(city)
|
@@ -92,14 +102,11 @@ if city:
|
|
92 |
st.write(f"π¨ Wind Speed: {wind_speed} m/s")
|
93 |
st.markdown("</div>", unsafe_allow_html=True)
|
94 |
|
95 |
-
# Get outfit suggestion based on weather
|
96 |
-
outfit_suggestion = get_outfit_suggestion(weather_condition)
|
97 |
if outfit_suggestion:
|
98 |
st.subheader("π Outfit Suggestion")
|
99 |
st.write(outfit_suggestion)
|
100 |
-
# Adding a fun emoji icon based on the weather condition
|
101 |
-
outfit_icon = "π" if "warm" in outfit_suggestion.lower() else "π§₯"
|
102 |
-
st.markdown(f"{outfit_icon} {outfit_suggestion}")
|
103 |
else:
|
104 |
st.warning("No outfit suggestion available for this weather condition.")
|
105 |
else:
|
@@ -109,6 +116,9 @@ else:
|
|
109 |
|
110 |
|
111 |
|
|
|
|
|
|
|
112 |
# import requests
|
113 |
# import streamlit as st
|
114 |
# import groq
|
|
|
26 |
st.error("Could not retrieve weather data. Please check your API key and city name.")
|
27 |
return None
|
28 |
|
29 |
+
# Function to get outfit suggestion from Groq text generation model
|
30 |
+
def get_outfit_suggestion(weather_condition, temperature, city, gender):
|
31 |
+
url = "https://api.groq.com/v1/completions" # Groq's text generation endpoint
|
32 |
headers = {
|
33 |
"Authorization": f"Bearer {groq_api_key}",
|
34 |
"Content-Type": "application/json"
|
35 |
}
|
36 |
+
|
37 |
+
# Construct a prompt based on the weather and user details
|
38 |
+
prompt = (
|
39 |
+
f"Suggest an outfit for a {gender} in {city} where the weather is {weather_condition} "
|
40 |
+
f"with a temperature of {temperature}Β°C. Make it practical and stylish."
|
41 |
+
)
|
42 |
+
|
43 |
payload = {
|
44 |
+
"model": "llama3-8b-8192", # Use an appropriate Groq model
|
45 |
+
"messages": [{"role": "user", "content": prompt}]
|
46 |
}
|
47 |
+
|
48 |
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
49 |
if response.status_code == 200:
|
50 |
+
return response.json().get("choices")[0]["message"]["content"]
|
51 |
else:
|
52 |
st.error("Could not retrieve outfit suggestions. Please check your Groq API.")
|
53 |
return None
|
|
|
81 |
|
82 |
# Try auto-detecting location if city is empty
|
83 |
city = st.text_input("Enter your location:", value=get_location_by_ip() or "")
|
84 |
+
gender = st.radio("Select Gender", options=["Male", "Female"], index=0)
|
85 |
|
86 |
if city:
|
87 |
weather_data = get_weather_data(city)
|
|
|
102 |
st.write(f"π¨ Wind Speed: {wind_speed} m/s")
|
103 |
st.markdown("</div>", unsafe_allow_html=True)
|
104 |
|
105 |
+
# Get outfit suggestion based on weather and gender
|
106 |
+
outfit_suggestion = get_outfit_suggestion(weather_condition, temperature, city, gender)
|
107 |
if outfit_suggestion:
|
108 |
st.subheader("π Outfit Suggestion")
|
109 |
st.write(outfit_suggestion)
|
|
|
|
|
|
|
110 |
else:
|
111 |
st.warning("No outfit suggestion available for this weather condition.")
|
112 |
else:
|
|
|
116 |
|
117 |
|
118 |
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
# import requests
|
123 |
# import streamlit as st
|
124 |
# import groq
|