|
import streamlit as st |
|
import requests |
|
import os |
|
from groq import Groq |
|
|
|
|
|
google_api_key = "AIzaSyBP5XGE4ZtrH2nBJZb7qe3Pjhw61rQvjBM" |
|
google_weather_api_url = "https://api.openweathermap.org/data/2.5/weather" |
|
|
|
|
|
groq_api_key = "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" |
|
client = Groq(api_key=groq_api_key) |
|
|
|
|
|
st.title("Real-time Weather App with Groq Integration") |
|
|
|
|
|
city = st.text_input("Enter city name") |
|
|
|
|
|
if city: |
|
|
|
params = { |
|
"q": city, |
|
"appid": google_api_key, |
|
"units": "metric" |
|
} |
|
|
|
try: |
|
response = requests.get(google_weather_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"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}") |
|
|
|
|
|
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}") |
|
|
|
|
|
|