tharunk07 commited on
Commit
d90c908
·
1 Parent(s): d1dd29a

Add application file

Browse files
Files changed (2) hide show
  1. app.py +21 -0
  2. weatherDetect.py +34 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import weatherDetect
3
+ st.title("Weather Detection")
4
+
5
+
6
+ city = st.text_input("Enter the city name:")
7
+
8
+ if st.button("Enter"):
9
+ if city:
10
+ result = weatherDetect.weather(city)
11
+ if isinstance(result, tuple):
12
+ current_temperature, current_humidity, weather_description = result
13
+
14
+ st.write(f"**City:** {city.capitalize()}")
15
+ st.write(f"**Current Temperature:** {current_temperature:.2f}°C")
16
+ st.write(f"**Current Humidity:** {current_humidity}%")
17
+ st.write(f"**Weather Description:** {weather_description.capitalize()}")
18
+ else:
19
+ st.write(result)
20
+ else:
21
+ st.write("Please enter a city name.")
weatherDetect.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests, json
2
+
3
+
4
+
5
+ def weather(s):
6
+ api_key = "147b1134e5c0d89525cc02377dc0940f"
7
+
8
+
9
+ base_url = "http://api.openweathermap.org/data/2.5/weather?"
10
+
11
+
12
+ city_name = s
13
+
14
+
15
+ complete_url = base_url + "appid=" + api_key + "&q=" + city_name
16
+
17
+ response = requests.get(complete_url)
18
+
19
+ x = response.json()
20
+ # print(x)
21
+ if x["cod"] != "404":
22
+
23
+ y = x["main"]
24
+ current_temperature = y["temp"]-273
25
+ # print(current_temperature)
26
+ current_humidity = y["humidity"]
27
+ z = x["weather"]
28
+ weather_description = str(z[0]["description"])
29
+ #print(x)
30
+ return current_temperature,current_humidity,weather_description
31
+ else:
32
+ return "No data found"
33
+
34
+