import streamlit as st import requests import os from groq import Groq # Set up API keys and URLs google_api_key = "AIzaSyBP5XGE4ZtrH2nBJZb7qe3Pjhw61rQvjBM" google_weather_api_url = "https://api.openweathermap.org/data/2.5/weather" # Set up Groq API groq_api_key = "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" client = Groq(api_key=groq_api_key) # Streamlit UI st.title("Real-time Weather App with Groq Integration") # City input city = st.text_input("Enter city name") # Weather data display if city: # Google Weather API request params = { "q": city, "appid": google_api_key, "units": "metric" # For temperature in Celsius; use "imperial" for Fahrenheit } try: response = requests.get(google_weather_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"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}") # Groq API request 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}") # Run the Streamlit app with `streamlit run your_script.py`