Spaces:
Sleeping
Sleeping
Delete app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import streamlit as stimport requestsimport pandas as pdimport altair as altfrom datetime import datetime
st.set_page_config(page_title="Climate Clock Dashboard", layout="wide")st.title("🌍 Real-Time Climate Clock Dashboard")
# Fetch Climate Clock API dataapi_url = "https://api.climateclock.world/v2/clock"response = requests.get(api_url)data = response.json()clock = data["data"]["clocks"]
# CO2 Budget Visualizationco2_clock = clock["co2"]co2_remaining = float(co2_clock["remaining"])co2_rate = float(co2_clock["rate"])projected_years = 10current_year = datetime.now().yearyears = list(range(current_year, current_year + projected_years))remaining_values = [co2_remaining - co2_rate * i for i in range(projected_years)]co2_df = pd.DataFrame({'Year': years, 'Remaining CO₂ Budget (Gt)': remaining_values})
st.subheader("💨 Projected CO₂ Budget Depletion (Next 10 Years)")co2_chart = alt.Chart(co2_df).mark_line(point=True).encode( x='Year:O', y='Remaining CO₂ Budget (Gt):Q', tooltip=['Year', 'Remaining CO₂ Budget (Gt)']).properties(width=700, height=400)st.altair_chart(co2_chart, use_container_width=True)
# Renewable Energy Progress Visualizationrenewables_clock = clock["renewables"]renewables_percent = float(renewables_clock["percentage"])renewable_df = pd.DataFrame({ 'Type': ['Renewables', 'Others'], 'Percentage': [renewables_percent, 100 - renewables_percent]})
st.subheader("⚡ Global Energy Source Share")renewable_chart = alt.Chart(renewable_df).mark_arc(innerRadius=50).encode( theta='Percentage:Q', color='Type:N', tooltip=['Type', 'Percentage']).properties(width=400, height=400)st.altair_chart(renewable_chart, use_container_width=True)
# Lifeline Sectionst.subheader("🌱 Lifeline Metrics")lifelines = clock["lifelines"]lifeline_data = [{'Label': l['label'], 'Value': float(l['value'])} for l in lifelines]lifeline_df = pd.DataFrame(lifeline_data)
lifeline_chart = alt.Chart(lifeline_df).mark_bar().encode( x=alt.X('Label:N', sort='-y'), y='Value:Q', tooltip=['Label', 'Value']).properties(width=700, height=400)st.altair_chart(lifeline_chart, use_container_width=True)
st.caption("Data source: Climate Clock API (https://climateclock.world)")app.pyDeleted-63