Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
-
import os
|
4 |
from groq import Groq
|
5 |
|
6 |
# Set up API keys and URLs
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
# Set up Groq API
|
11 |
groq_api_key = "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"
|
@@ -19,16 +19,20 @@ city = st.text_input("Enter city name")
|
|
19 |
|
20 |
# Weather data display
|
21 |
if city:
|
22 |
-
#
|
23 |
params = {
|
24 |
"q": city,
|
25 |
-
"appid":
|
26 |
"units": "metric" # For temperature in Celsius; use "imperial" for Fahrenheit
|
27 |
}
|
28 |
|
29 |
try:
|
30 |
-
response = requests.get(
|
31 |
response.raise_for_status() # Will raise an HTTPError for bad responses
|
|
|
|
|
|
|
|
|
32 |
weather_data = response.json()
|
33 |
|
34 |
if weather_data.get("cod") != 200:
|
@@ -61,4 +65,4 @@ if city:
|
|
61 |
except Exception as e:
|
62 |
st.write(f"Error fetching Groq data: {e}")
|
63 |
|
64 |
-
#
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
|
|
3 |
from groq import Groq
|
4 |
|
5 |
# Set up API keys and URLs
|
6 |
+
# Use your OpenWeatherMap API key
|
7 |
+
openweather_api_key = "2f3389762791167fbac751eed085d0ef"
|
8 |
+
openweather_api_url = "https://api.openweathermap.org/data/2.5/weather"
|
9 |
|
10 |
# Set up Groq API
|
11 |
groq_api_key = "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"
|
|
|
19 |
|
20 |
# Weather data display
|
21 |
if city:
|
22 |
+
# OpenWeatherMap API request
|
23 |
params = {
|
24 |
"q": city,
|
25 |
+
"appid": openweather_api_key,
|
26 |
"units": "metric" # For temperature in Celsius; use "imperial" for Fahrenheit
|
27 |
}
|
28 |
|
29 |
try:
|
30 |
+
response = requests.get(openweather_api_url, params=params)
|
31 |
response.raise_for_status() # Will raise an HTTPError for bad responses
|
32 |
+
|
33 |
+
# Print raw response for debugging
|
34 |
+
st.write(f"Raw response: {response.text}")
|
35 |
+
|
36 |
weather_data = response.json()
|
37 |
|
38 |
if weather_data.get("cod") != 200:
|
|
|
65 |
except Exception as e:
|
66 |
st.write(f"Error fetching Groq data: {e}")
|
67 |
|
68 |
+
# Note: Make sure to replace "YOUR_OPENWEATHERMAP_API_KEY" with your actual OpenWeatherMap API key.
|