Spaces:
Build error
Build error
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import faiss | |
| # Set page configuration | |
| st.set_page_config( | |
| page_title="Crop Yield Predictor", | |
| page_icon="🌾", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Header with title and local image | |
| st.markdown("<h1 style='text-align: center; color: green;'>🌾 Crop Yield Prediction and Recommendations 🌱</h1>", unsafe_allow_html=True) | |
| # Try loading the local image | |
| try: | |
| st.image("./assets/agriculture_image.png", use_column_width=True) # Ensure path is correct | |
| except Exception: | |
| st.warning("Image not found. Please check if 'agriculture_image.png' exists in the 'assets/' folder.") | |
| # Sidebar for uploading CSV | |
| st.sidebar.header("Upload Crop Data CSV") | |
| uploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv"]) | |
| # Check if file is uploaded | |
| if uploaded_file is not None: | |
| data = pd.read_csv(uploaded_file) | |
| st.sidebar.success("File uploaded successfully!") | |
| # Display uploaded data | |
| st.write("### Uploaded Data") | |
| st.dataframe(data.head()) | |
| # Select ID for prediction | |
| id_column = st.sidebar.selectbox("Select ID Column", options=data.columns) | |
| selected_id = st.sidebar.selectbox("Select ID", options=data[id_column].unique()) | |
| # Dummy FAISS-based recommendation | |
| def dummy_recommendation(df, selected_id): | |
| # Filter data for selected ID (replace with actual FAISS logic) | |
| selected_data = df[df[id_column] == selected_id].iloc[0] | |
| recommendations = { | |
| "Crop Type": "Wheat", | |
| "Optimal pH": "6.0 - 7.0", | |
| "Soil Recommendation": "Loamy Soil", | |
| "Watering Schedule": "Twice a week" | |
| } | |
| return recommendations | |
| # Display prediction and recommendations | |
| if st.button("Get Recommendations"): | |
| st.write(f"### Recommendations for ID: {selected_id}") | |
| recommendations = dummy_recommendation(data, selected_id) | |
| for key, value in recommendations.items(): | |
| st.markdown(f"<p style='font-size: 18px;'><strong>{key}:</strong> {value}</p>", unsafe_allow_html=True) | |
| else: | |
| st.warning("Please upload a CSV file to proceed.") | |
| # Footer | |
| st.markdown("---") | |
| st.markdown("<h3 style='text-align: center;'>Made with ❤️ for Sustainable Agriculture 🌱</h3>", unsafe_allow_html=True) | |
| st.markdown("<p style='text-align: center;'>Powered by Streamlit</p>", unsafe_allow_html=True) | |