|
import streamlit as st |
|
import requests |
|
from groq import Groq |
|
|
|
|
|
|
|
openweather_api_key = "aa4db8152e46c2f3fb19fad5d58a0ed8ddssd" |
|
openweather_api_url = "https://api.openweathermap.org/data/2.5/weather" |
|
|
|
|
|
groq_api_key = "gsk_loI5Z6fHhtPZo25YmryjWGdyb3FYdfrw1oxGVCfZkwXRE79BAgHCO7c" |
|
client = Groq(api_key=groq_api_key) |
|
|
|
|
|
st.title("Real-time Weather App") |
|
|
|
|
|
city = st.text_input("Enter city name") |
|
|
|
|
|
if city: |
|
|
|
params = { |
|
"q": city, |
|
"appid": openweather_api_key, |
|
"units": "metric" |
|
} |
|
|
|
try: |
|
response = requests.get(openweather_api_url, params=params) |
|
response.raise_for_status() |
|
|
|
weather_data = response.json() |
|
|
|
if weather_data.get("cod") != 200: |
|
st.write(f"Error fetching weather data: {weather_data.get('message', 'Unknown error')}") |
|
else: |
|
|
|
st.write("Current Weather:") |
|
st.write(f"City: {weather_data['name']}, {weather_data['sys']['country']}") |
|
st.write(f"Temperature: {weather_data['main']['temp']}°C") |
|
st.write(f"Weather: {weather_data['weather'][0]['description'].capitalize()}") |
|
st.write(f"Humidity: {weather_data['main']['humidity']}%") |
|
st.write(f"Wind Speed: {weather_data['wind']['speed']} m/s") |
|
|
|
except requests.exceptions.RequestException as e: |
|
st.write(f"Error fetching weather data: {e}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|