Spaces:
Build error
Build error
| import streamlit as st | |
| import pandas as pd | |
| # Load the cleaned data | |
| df = pd.read_csv('cleaned_farmer_data.csv') | |
| # Set the page configuration for better layout and dark theme | |
| st.set_page_config( | |
| page_title="Agroforestry Program Dashboard", | |
| page_icon="π±", | |
| layout="wide", | |
| ) | |
| # Custom CSS for dark theme and background color adjustments | |
| st.markdown(""" | |
| <style> | |
| body { | |
| background-color: #121212; /* Dark background color */ | |
| color: white; /* Text color set to white */ | |
| } | |
| .sidebar .sidebar-content { | |
| background-color: #1e1e1e; /* Dark sidebar background */ | |
| color: white; /* Sidebar text color */ | |
| } | |
| .stButton>button { | |
| background-color: #4CAF50; /* Green button color */ | |
| color: white; /* Button text color */ | |
| } | |
| .title { | |
| text-align: center; | |
| font-size: 40px; | |
| color: #4CAF50; | |
| } | |
| .stMarkdown { | |
| background-color: #1e1e1e; /* Dark background for markdown blocks */ | |
| } | |
| .stTable { | |
| background-color: #1e1e1e; /* Dark background for table blocks */ | |
| } | |
| .stDataFrame { | |
| background-color: #1e1e1e; /* Dark background for dataframe */ | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Title and header for the dashboard | |
| st.markdown('<div class="title">Real-Time Insights for Farmers</div>', unsafe_allow_html=True) | |
| # Sidebar for navigation with a cleaner layout | |
| st.sidebar.header("Dashboard Navigation") | |
| section = st.sidebar.radio( | |
| "Select a Section:", | |
| ['Overview', 'Data Quality Issues', 'Plantation Progress', 'Location Insights'] | |
| ) | |
| # Overview Section | |
| if section == 'Overview': | |
| st.subheader("π Overall Statistics") | |
| # Display key metrics in a clean, organized way | |
| total_area = df['total_land_area_acre'].sum() # Corrected column name | |
| total_plantation_area = df['area_f4f_acre'].sum() # Assuming 'area_f4f_acre' represents plantation area | |
| # Calculate the number of rows with missing or erroneous data | |
| missing_data_count = df.isnull().sum().sum() # Total missing values in the dataset | |
| st.markdown(f""" | |
| <div style="display: flex; justify-content: space-around; margin-top: 20px;"> | |
| <div style="padding: 10px; background-color: #333333; border-radius: 8px; width: 30%; text-align: center;"> | |
| <h3>Total Area (Acres)</h3> | |
| <p style="font-size: 30px; color: #4CAF50;">{total_area}</p> | |
| </div> | |
| <div style="padding: 10px; background-color: #333333; border-radius: 8px; width: 30%; text-align: center;"> | |
| <h3>Total Plantation Area (Acres)</h3> | |
| <p style="font-size: 30px; color: #4CAF50;">{total_plantation_area}</p> | |
| </div> | |
| <div style="padding: 10px; background-color: #333333; border-radius: 8px; width: 30%; text-align: center;"> | |
| <h3>Missing Data Entries</h3> | |
| <p style="font-size: 30px; color: #f44336;">{missing_data_count}</p> | |
| </div> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Data Quality Issues Section | |
| elif section == 'Data Quality Issues': | |
| st.subheader("β οΈ Data Quality Issues") | |
| # Check for missing or erroneous data | |
| missing_data = df[df.isnull().any(axis=1)] # Rows with missing values | |
| # Search functionality to filter results by farmer name | |
| search_term = st.text_input("π Search by Farmer Name", "").strip().lower() | |
| if search_term: | |
| missing_data = missing_data[missing_data['farmer_name'].str.lower().str.contains(search_term)] | |
| if not missing_data.empty: | |
| st.write(f"**Displaying {len(missing_data)} records with data quality issues:**") | |
| st.dataframe(missing_data) | |
| else: | |
| st.write("π No data quality issues found!") | |
| # Plantation Progress Section | |
| elif section == 'Plantation Progress': | |
| st.subheader("πΏ Plantation Progress") | |
| # Check if plantation area percentage data exists | |
| if 'area_f4f_acre' in df.columns and 'total_land_area_acre' in df.columns: | |
| df['plantation_area_percentage'] = (df['area_f4f_acre'] / df['total_land_area_acre']) * 100 | |
| st.bar_chart(df['plantation_area_percentage']) | |
| else: | |
| st.warning("β οΈ No plantation progress data available!") | |
| # Location Insights Section | |
| elif section == 'Location Insights': | |
| st.subheader("π Plantation Area by Location") | |
| # Display the plantation area by district or location | |
| if 'District' in df.columns and 'area_f4f_acre' in df.columns: | |
| location_distribution = df.groupby('District')['area_f4f_acre'].sum().reset_index() | |
| st.bar_chart(location_distribution.set_index('District')['area_f4f_acre']) | |
| else: | |
| st.warning("β οΈ Location or plantation area data is missing!") | |
| # Footer with contact info | |
| st.markdown(""" | |
| --- | |
| **Developed by:** [Satyam Kumar](https://github.com/Satyam0775) | |
| **π§ Contact:** Satyamrishav0013@gmail.com | |
| """) |