abdullahzunorain
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -30,22 +30,22 @@ def parse_weather_data(weather_data):
|
|
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):
|
49 |
# Initialize Groq's API
|
50 |
try:
|
51 |
client = groq.Groq(api_key=groq_api_key) # Use the secret API key
|
@@ -58,17 +58,63 @@ def get_outfit_suggestion(temperature, description, style, fabric, weather_categ
|
|
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()
|
62 |
except Exception as e:
|
63 |
st.error(f"Error using Groq API: {e}")
|
64 |
-
return None
|
65 |
|
66 |
# Streamlit UI for user input
|
67 |
-
st.
|
68 |
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
#
|
|
|
|
|
|
|
72 |
style = st.selectbox("Select your preferred style", ["Casual", "Formal", "Sporty", "Business", "Chic"])
|
73 |
fabric = st.selectbox("Select your preferred fabric", ["Cotton", "Linen", "Wool", "Polyester", "Silk", "Leather"])
|
74 |
|
@@ -78,19 +124,19 @@ if city:
|
|
78 |
if weather_data and weather_data["cod"] == 200:
|
79 |
temperature, description = parse_weather_data(weather_data)
|
80 |
# Categorize the weather
|
81 |
-
weather_category = categorize_weather(description)
|
82 |
|
83 |
# Display current weather info
|
84 |
st.write(f"Current temperature in {city}: {temperature}°C")
|
85 |
-
st.write(f"Weather: {description}")
|
86 |
-
st.write(f"Weather Category: {weather_category}")
|
87 |
|
88 |
# Get outfit suggestion based on user preferences
|
89 |
-
outfit_suggestion = get_outfit_suggestion(temperature, description, style, fabric, weather_category)
|
90 |
|
91 |
if outfit_suggestion:
|
92 |
# Display outfit suggestion
|
93 |
-
st.
|
94 |
st.write(outfit_suggestion)
|
95 |
|
96 |
# Display weather icon
|
@@ -104,9 +150,6 @@ if city:
|
|
104 |
st.markdown(
|
105 |
"""
|
106 |
<style>
|
107 |
-
.reportview-container {
|
108 |
-
background: #f5f5f5;
|
109 |
-
}
|
110 |
.stButton>button {
|
111 |
background-color: #ff5733;
|
112 |
color: white;
|
@@ -120,7 +163,6 @@ st.markdown(
|
|
120 |
|
121 |
|
122 |
|
123 |
-
|
124 |
# import requests
|
125 |
# import streamlit as st
|
126 |
# import groq
|
|
|
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
|
|
|
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 |
+
# Style and fabric preferences
|
118 |
style = st.selectbox("Select your preferred style", ["Casual", "Formal", "Sporty", "Business", "Chic"])
|
119 |
fabric = st.selectbox("Select your preferred fabric", ["Cotton", "Linen", "Wool", "Polyester", "Silk", "Leather"])
|
120 |
|
|
|
124 |
if weather_data and weather_data["cod"] == 200:
|
125 |
temperature, description = parse_weather_data(weather_data)
|
126 |
# Categorize the weather
|
127 |
+
weather_category, weather_icon = categorize_weather(description)
|
128 |
|
129 |
# Display current weather info
|
130 |
st.write(f"Current temperature in {city}: {temperature}°C")
|
131 |
+
st.write(f"Weather: {description} {weather_icon}")
|
132 |
+
st.write(f"Weather Category: {weather_category} {weather_icon}")
|
133 |
|
134 |
# Get outfit suggestion based on user preferences
|
135 |
+
outfit_suggestion, weather_icon = get_outfit_suggestion(temperature, description, style, fabric, weather_category, weather_icon)
|
136 |
|
137 |
if outfit_suggestion:
|
138 |
# Display outfit suggestion
|
139 |
+
st.markdown(f"### 🌟 Outfit Suggestion 🌟")
|
140 |
st.write(outfit_suggestion)
|
141 |
|
142 |
# Display weather icon
|
|
|
150 |
st.markdown(
|
151 |
"""
|
152 |
<style>
|
|
|
|
|
|
|
153 |
.stButton>button {
|
154 |
background-color: #ff5733;
|
155 |
color: white;
|
|
|
163 |
|
164 |
|
165 |
|
|
|
166 |
# import requests
|
167 |
# import streamlit as st
|
168 |
# import groq
|