import streamlit as st import requests from groq import Groq # Set up API keys and URLs # Use your OpenWeatherMap API key openweather_api_key = "aa4db8152e46c2f3fb19fad5d58a0ed8ddssd" openweather_api_url = "https://api.openweathermap.org/data/2.5/weather" # Set up Groq API groq_api_key = "gsk_loI5Z6fHhtPZo25YmryjWGdyb3FYdfrw1oxGVCfZkwXRE79BAgHCO7c" client = Groq(api_key=groq_api_key) # Streamlit UI st.title("Real-time Weather App") # City input city = st.text_input("Enter city name") # Weather data display if city: # OpenWeatherMap API request params = { "q": city, "appid": openweather_api_key, "units": "metric" # For temperature in Celsius; use "imperial" for Fahrenheit } try: response = requests.get(openweather_api_url, params=params) response.raise_for_status() # Will raise an HTTPError for bad responses weather_data = response.json() if weather_data.get("cod") != 200: st.write(f"Error fetching weather data: {weather_data.get('message', 'Unknown error')}") else: # Display weather data 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}") # Remove Groq API request and response handling # try: # chat_completion = client.chat.completions.create( # messages=[ # { # "role": "user", # "content": "Explain the importance of fast language models", # } # ], # model="llama3-8b-8192", # ) # st.write("Groq AI Response:") # st.write(chat_completion.choices[0].message.content) # except Exception as e: # st.write(f"Error fetching Groq data: {e}")