Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please add CSS and other Aesthetics for my app.py code below: import streamlit as st import requests from streamlit _ folium import folium _ static

Please add CSS and other Aesthetics for my app.py code below:
import streamlit as st
import requests
from streamlit_folium import folium_static
import folium
import plotly.graph_objs as go
api_key = "YOUR_API_KEY_HERE"
st.title("Weather and Air Quality Web App")
st.header("Streamlit and AirVisual API")
@st.cache_data
def generate_list_of_countries():
countries_url = "YOUR_API_KEY_HERE"
countries_dict = requests.get(countries_url).json()
return countries_dict
@st.cache_data
def generate_list_of_states(country_selected):
states_url ="YOUR_API_KEY_HERE"
states_dict = requests.get(states_url).json()
return states_dict
@st.cache_data
def generate_list_of_cities(state_selected, country_selected):
cities_url ="YOUR_API_KEY_HERE"
cities_dict = requests.get(cities_url).json()
return cities_dict
def display_data(data):
st.write("**Temperature:**", data["current"]["weather"]["tp"],"\deg C")
st.write("**Humidity:**", data["current"]["weather"]["hu"],"%")
st.write("**Air Quality Index (AQI):**", data["current"]["pollution"]["aqius"])
def map_creator(latitude, longitude):
m = folium.Map(location=[latitude, longitude], zoom_start=10)
folium.Marker([latitude, longitude], popup="Location", tooltip="Location").add_to(m)
folium_static(m)
category = st.selectbox("Select location method", ["By City, State, and Country", "By Nearest City (IP Address)","By Latitude and Longitude"])
if category =="By City, State, and Country":
countries_dict = generate_list_of_countries()
if countries_dict["status"]== "success":
countries_list =[i["country"] for i in countries_dict["data"]]
countries_list.insert(0,"")
country_selected = st.selectbox("Select a country", options=countries_list)
if country_selected:
states_dict = generate_list_of_states(country_selected)
if states_dict["status"]== "success":
states_list =[i["state"] for i in states_dict["data"]]
states_list.insert(0,"")
state_selected = st.selectbox("Select a state", options=states_list)
if state_selected:
cities_dict = generate_list_of_cities(state_selected, country_selected)
if cities_dict["status"]== "success":
cities_list =[i["city"] for i in cities_dict["data"]]
cities_list.insert(0,"")
city_selected = st.selectbox("Select a city", options=cities_list)
if city_selected:
aqi_data_url ="YOUR_API_KEY_HERE"
aqi_data_dict = requests.get(aqi_data_url).json()
if aqi_data_dict["status"]== "success":
display_data(aqi_data_dict["data"])
map_creator(aqi_data_dict["data"]["location"]["coordinates"][1], aqi_data_dict["data"]["location"]["coordinates"][0])
else:
st.warning("No data available for this location.")
else:
st.warning("No cities available, please select another state.")
else:
st.warning("No states available, please select another country.")
else:
st.error("Too many requests. Wait for a few minutes before your next API call.")
elif category =="By Nearest City (IP Address)":
url ="YOUR_API_KEY_HERE"= requests.get(url).json()
if aqi_data_dict["status"]== "success":
display_data(aqi_data_dict["data"])
map_creator(aqi_data_dict["data"]["location"]["coordinates"][1], aqi_data_dict["data"]["location"]["coordinates"][0])
else:
st.warning("No data available for this location.")
elif category =="By Latitude and Longitude":
latitude = st.text_input("Enter latitude")
longitude = st.text_input("Enter longitude")
if latitude and longitude:
url ="YOUR_API_KEY_HERE"
aqi_data_dict = requests.get(url).json()
if aqi_data_dict["status"]== "success":
display_data(aqi_data_dict["data"])
map_creator(aqi_data_dict["data"]["location"]["coordinates"][1], aqi_data_dict["data"]["location"]["coordinates"][0])
else:
st.warning("No data available for this location.")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions