File size: 2,237 Bytes
e444d5a
 
 
 
 
2b03ad3
0682d23
2b03ad3
e444d5a
 
0682d23
e444d5a
 
 
50de7f0
e444d5a
 
 
 
 
 
2b03ad3
e444d5a
 
2b03ad3
e444d5a
 
 
 
2b03ad3
e444d5a
2b03ad3
e444d5a
 
 
 
 
 
 
a323f6c
e444d5a
 
 
 
 
 
 
 
a323f6c
 
 
 
 
 
 
 
 
 
 
 
 
e444d5a
a323f6c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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}")