Spaces:
Runtime error
Runtime error
implemented code
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
+
from geopy.geocoders import GoogleV3
|
5 |
+
from text2image import generate_image
|
6 |
+
import streamlit as st
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
API_KEY = os.getenv('WEATHER_API')
|
10 |
+
GOOGLE_API = os.getenv('GOOGLE_API')
|
11 |
+
geolocator = GoogleV3(api_key=GOOGLE_API)
|
12 |
+
|
13 |
+
st.title("Weather Image")
|
14 |
+
|
15 |
+
user_input = st.text_input('Provide Location Below')
|
16 |
+
submit = st.button("Submit", type="primary")
|
17 |
+
|
18 |
+
# Use for demonstration
|
19 |
+
# CITY = 'London'
|
20 |
+
# url = f"https://api.openweathermap.org/data/2.5/weather?q={CITY}&appid={API_KEY}"
|
21 |
+
|
22 |
+
|
23 |
+
if user_input and submit:
|
24 |
+
location = geolocator.geocode(user_input)
|
25 |
+
url = f"https://api.openweathermap.org/data/2.5/weather?lat={location.latitude}&lon={location.longitude}&appid={API_KEY}"
|
26 |
+
response = requests.get(url).json()
|
27 |
+
|
28 |
+
city = response['name']
|
29 |
+
weather = response["weather"][0]["main"]
|
30 |
+
country = response["sys"]["country"]
|
31 |
+
description = response["weather"][0]["description"]
|
32 |
+
|
33 |
+
image_url = generate_image(city, weather, country, description)
|
34 |
+
st.image(image_url, caption=f"{weather} in {location},{country}")
|
35 |
+
|
36 |
+
|