Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -192,10 +192,7 @@ def ev_insights():
|
|
| 192 |
|
| 193 |
|
| 194 |
def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=2009, end_year=2025):
|
| 195 |
-
<<<<<<< HEAD
|
| 196 |
|
| 197 |
-
=======
|
| 198 |
-
>>>>>>> b8597d17346ea9ab17065cb28941f11c8f958d1b
|
| 199 |
# Folder paths
|
| 200 |
folders = {
|
| 201 |
"statewise": os.path.join(root_dir, "Fuel_vs_state"),
|
|
@@ -232,10 +229,6 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
|
|
| 232 |
combined_df = pd.concat([combined_df, df], ignore_index=True)
|
| 233 |
return combined_df
|
| 234 |
|
| 235 |
-
<<<<<<< HEAD
|
| 236 |
-
=======
|
| 237 |
-
# Load all data
|
| 238 |
-
>>>>>>> b8597d17346ea9ab17065cb28941f11c8f958d1b
|
| 239 |
statewise_df = load_data_for_year_range(folders["statewise"], start_year, end_year)
|
| 240 |
norms_df = load_data_for_year_range(folders["norms"], start_year, end_year)
|
| 241 |
fuelwise_df = load_data_for_year_range(folders["fuelwise"], start_year, end_year)
|
|
@@ -248,10 +241,6 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
|
|
| 248 |
"🔥 Emission by Fuel Type"
|
| 249 |
])
|
| 250 |
|
| 251 |
-
<<<<<<< HEAD
|
| 252 |
-
=======
|
| 253 |
-
# Tab 1
|
| 254 |
-
>>>>>>> b8597d17346ea9ab17065cb28941f11c8f958d1b
|
| 255 |
with tab1:
|
| 256 |
st.subheader("Fuel Distribution Across States")
|
| 257 |
if not statewise_df.empty:
|
|
@@ -271,10 +260,6 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
|
|
| 271 |
labels={"Fuel_Amount": "Amount (in units)"}, barmode="group")
|
| 272 |
st.plotly_chart(fig1, use_container_width=True)
|
| 273 |
|
| 274 |
-
<<<<<<< HEAD
|
| 275 |
-
=======
|
| 276 |
-
# Tab 2
|
| 277 |
-
>>>>>>> b8597d17346ea9ab17065cb28941f11c8f958d1b
|
| 278 |
with tab2:
|
| 279 |
st.subheader("Emission Norm Distribution by State")
|
| 280 |
if not norms_df.empty:
|
|
@@ -294,7 +279,6 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
|
|
| 294 |
labels={"Count": "Count of Norms"}, barmode="group")
|
| 295 |
st.plotly_chart(fig2, use_container_width=True)
|
| 296 |
|
| 297 |
-
<<<<<<< HEAD
|
| 298 |
with tab3:
|
| 299 |
st.subheader("Norm Emissions by Fuel Type and Year")
|
| 300 |
|
|
@@ -332,37 +316,6 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
|
|
| 332 |
norm_vs_category_combined = pd.concat([norm_vs_category_combined, norm_df], ignore_index=True)
|
| 333 |
except Exception as e:
|
| 334 |
st.warning(f"Error loading data for {year}: {e}")
|
| 335 |
-
=======
|
| 336 |
-
# Tab 3
|
| 337 |
-
with tab3:
|
| 338 |
-
st.subheader("Norm Emissions by Fuel Type")
|
| 339 |
-
if not fuelwise_df.empty:
|
| 340 |
-
norm_columns = [col for col in fuelwise_df.columns if col not in ["Fuel", "Year"]]
|
| 341 |
-
if "Fuel" in fuelwise_df.columns and norm_columns:
|
| 342 |
-
melted_fuelwise = pd.melt(fuelwise_df, id_vars=["Fuel", "Year"],
|
| 343 |
-
var_name="Norm_Type", value_name="Emission")
|
| 344 |
-
melted_fuelwise = melted_fuelwise.dropna()
|
| 345 |
-
melted_fuelwise["Emission"] = pd.to_numeric(melted_fuelwise["Emission"], errors="coerce")
|
| 346 |
-
melted_fuelwise = melted_fuelwise.dropna(subset=["Emission"])
|
| 347 |
-
|
| 348 |
-
selected_fuels = st.multiselect("Select Fuel Types", ["Select All"] + sorted(melted_fuelwise["Fuel"].unique()), default=[], key="fuel_selection")
|
| 349 |
-
if "Select All" in selected_fuels:
|
| 350 |
-
selected_fuels = list(melted_fuelwise["Fuel"].unique())
|
| 351 |
-
|
| 352 |
-
year_range = st.slider("Select Year Range", min_value=start_year, max_value=end_year, value=(start_year, end_year), key="fuel_year")
|
| 353 |
-
filtered_fuelwise = melted_fuelwise[(melted_fuelwise["Fuel"].isin(selected_fuels)) &
|
| 354 |
-
(melted_fuelwise["Year"].between(year_range[0], year_range[1]))]
|
| 355 |
-
|
| 356 |
-
fig3 = px.bar(filtered_fuelwise, x="Fuel", y="Emission", color="Norm_Type",
|
| 357 |
-
title=f"Emission per Fuel Type from {year_range[0]} to {year_range[1]}",
|
| 358 |
-
labels={"Emission": "Emission Amount"}, barmode="stack")
|
| 359 |
-
st.plotly_chart(fig3, use_container_width=True)
|
| 360 |
-
|
| 361 |
-
st.subheader("Top Fuels Emitting Most Pollution")
|
| 362 |
-
top_fuels = filtered_fuelwise.groupby("Fuel")["Emission"].sum().reset_index()
|
| 363 |
-
top_fuels_sorted = top_fuels.sort_values(by="Emission", ascending=False).head(10)
|
| 364 |
-
st.write(top_fuels_sorted)
|
| 365 |
-
>>>>>>> b8597d17346ea9ab17065cb28941f11c8f958d1b
|
| 366 |
|
| 367 |
fuel_options = sorted(fuel_vs_norm_combined['fuel'].dropna().unique())
|
| 368 |
category_options = sorted(norm_vs_category_combined['vehicle_category'].dropna().unique())
|
|
@@ -718,16 +671,9 @@ def ask_with_llm():
|
|
| 718 |
|
| 719 |
# Download option
|
| 720 |
csv = result.to_csv(index=False).encode('utf-8')
|
| 721 |
-
<<<<<<< HEAD
|
| 722 |
st.download_button("⬇️ Download Result as CSV", data=csv, file_name="query_result.csv", mime='text/csv')
|
| 723 |
|
| 724 |
st.plotly_chart(fig)
|
| 725 |
-
=======
|
| 726 |
-
st.download_button("⬇ Download Result as CSV", data=csv, file_name="query_result.csv", mime='text/csv')
|
| 727 |
-
|
| 728 |
-
st.plotly_chart(fig)
|
| 729 |
-
|
| 730 |
-
>>>>>>> b8597d17346ea9ab17065cb28941f11c8f958d1b
|
| 731 |
|
| 732 |
|
| 733 |
# Run the entire app
|
|
@@ -762,8 +708,4 @@ elif section == "Ask with Text (LLM)":
|
|
| 762 |
st.markdown("- Norm-wise registrations in Maharashtra in 2024 ")
|
| 763 |
st.markdown("- Electric (EV) norm-wise registrations in Karnataka after 2021 ")
|
| 764 |
st.markdown("- Fuel-wise registrations in Delhi in 2020")
|
| 765 |
-
<<<<<<< HEAD
|
| 766 |
st.markdown("- Vehicle classes by registrations in Tamil Nadu in 2022 ")
|
| 767 |
-
=======
|
| 768 |
-
st.markdown("- Vehicle classes by registrations in Tamil Nadu in 2022 ")
|
| 769 |
-
>>>>>>> b8597d17346ea9ab17065cb28941f11c8f958d1b
|
|
|
|
| 192 |
|
| 193 |
|
| 194 |
def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=2009, end_year=2025):
|
|
|
|
| 195 |
|
|
|
|
|
|
|
| 196 |
# Folder paths
|
| 197 |
folders = {
|
| 198 |
"statewise": os.path.join(root_dir, "Fuel_vs_state"),
|
|
|
|
| 229 |
combined_df = pd.concat([combined_df, df], ignore_index=True)
|
| 230 |
return combined_df
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
statewise_df = load_data_for_year_range(folders["statewise"], start_year, end_year)
|
| 233 |
norms_df = load_data_for_year_range(folders["norms"], start_year, end_year)
|
| 234 |
fuelwise_df = load_data_for_year_range(folders["fuelwise"], start_year, end_year)
|
|
|
|
| 241 |
"🔥 Emission by Fuel Type"
|
| 242 |
])
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
with tab1:
|
| 245 |
st.subheader("Fuel Distribution Across States")
|
| 246 |
if not statewise_df.empty:
|
|
|
|
| 260 |
labels={"Fuel_Amount": "Amount (in units)"}, barmode="group")
|
| 261 |
st.plotly_chart(fig1, use_container_width=True)
|
| 262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
with tab2:
|
| 264 |
st.subheader("Emission Norm Distribution by State")
|
| 265 |
if not norms_df.empty:
|
|
|
|
| 279 |
labels={"Count": "Count of Norms"}, barmode="group")
|
| 280 |
st.plotly_chart(fig2, use_container_width=True)
|
| 281 |
|
|
|
|
| 282 |
with tab3:
|
| 283 |
st.subheader("Norm Emissions by Fuel Type and Year")
|
| 284 |
|
|
|
|
| 316 |
norm_vs_category_combined = pd.concat([norm_vs_category_combined, norm_df], ignore_index=True)
|
| 317 |
except Exception as e:
|
| 318 |
st.warning(f"Error loading data for {year}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
|
| 320 |
fuel_options = sorted(fuel_vs_norm_combined['fuel'].dropna().unique())
|
| 321 |
category_options = sorted(norm_vs_category_combined['vehicle_category'].dropna().unique())
|
|
|
|
| 671 |
|
| 672 |
# Download option
|
| 673 |
csv = result.to_csv(index=False).encode('utf-8')
|
|
|
|
| 674 |
st.download_button("⬇️ Download Result as CSV", data=csv, file_name="query_result.csv", mime='text/csv')
|
| 675 |
|
| 676 |
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
|
| 678 |
|
| 679 |
# Run the entire app
|
|
|
|
| 708 |
st.markdown("- Norm-wise registrations in Maharashtra in 2024 ")
|
| 709 |
st.markdown("- Electric (EV) norm-wise registrations in Karnataka after 2021 ")
|
| 710 |
st.markdown("- Fuel-wise registrations in Delhi in 2020")
|
|
|
|
| 711 |
st.markdown("- Vehicle classes by registrations in Tamil Nadu in 2022 ")
|
|
|
|
|
|
|
|
|