Spaces:
Sleeping
Sleeping
| # Import python libraries | |
| import streamlit as st | |
| import seaborn as sns | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import os # Import the os module for path manipulation | |
| # Get the directory of the current script | |
| script_dir = os.path.dirname(__file__) | |
| # Construct the full path to the CSV file | |
| # Assuming avocado.csv is in the same directory as streamlit_app.py | |
| csv_file_path = os.path.join(script_dir, "avocado.csv") | |
| # Data Set | |
| try: | |
| df = pd.read_csv(csv_file_path) | |
| # Defining Count Graph/Plot | |
| st.title("Avocado Sales Count by Year") | |
| fig = plt.figure(figsize=(10, 5)) | |
| sns.countplot(x="year", data=df) | |
| plt.title("Number of Avocado Sales Records per Year") # Add a title to the plot | |
| plt.xlabel("Year") # Label for the x-axis | |
| plt.ylabel("Count of Records") # Label for the y-axis | |
| st.pyplot(fig) | |
| except FileNotFoundError: | |
| st.error(f"Error: The file '{csv_file_path}' was not found.") | |
| st.info("Please ensure 'avocado.csv' is in the same directory as 'streamlit_app.py' inside your Docker container's 'src' directory.") | |
| except pd.errors.EmptyDataError: | |
| st.error(f"Error: The file '{csv_file_path}' is empty.") | |
| st.info("Please ensure 'avocado.csv' contains data.") | |
| except Exception as e: | |
| st.error(f"An unexpected error occurred while loading data or plotting: {e}") | |