Spaces:
Runtime error
Runtime error
Download app2.py from Silverxwolf/FoodQast: direct link, hf CLI and curl.
- Browser
- Download file 3.97 kB
-
https://huggingface.co/spaces/Silverxwolf/FoodQast/resolve/main/app2.py
- Command line
-
hf download hf://spaces/Silverxwolf/FoodQast/app2.py
-
curl -L -o app2.py https://huggingface.co/spaces/Silverxwolf/FoodQast/resolve/main/app2.py
3.97 kB
| import streamlit as st | |
| import matplotlib.pyplot as plt | |
| import matplotlib | |
| from functions import * | |
| from dataset import get_dataset, get_columns, get_optional_params | |
| from format import validate_and_formate_columns, filter_selected_options, valid_rows_number | |
| from data_prep import get_frequency, tmp_renaming_columns, get_dates, split_dataset, get_forecast_dates | |
| from forecast import forecast_models | |
| from visualise import visualise_data, visualise_evaluation, display_evaluation, visualise_forecast, remove_watermark | |
| font = {'weight' : 'normal', | |
| 'size' : 18} | |
| matplotlib.rc('font', **font) | |
| def main(): | |
| remove_watermark() | |
| st.title("FoodQast") | |
| st.sidebar.title("1. Data") | |
| # Load data from uploaded dataset | |
| with st.sidebar.expander("Dataset", expanded=True): | |
| files, datasets, load_options = get_dataset() | |
| check_upload_status(files["file"], files["recipe_file"]) | |
| # sidebar setting if files are uploaded | |
| if files["file"] and files["recipe_file"]: | |
| with st.sidebar.expander("Columns", expanded=True): | |
| columns = get_columns(datasets, load_options) | |
| validate_and_formate_columns(datasets, columns, load_options) | |
| with st.sidebar.expander("Optional columns"): | |
| datasets, columns, load_options = get_optional_params(datasets, columns, load_options) | |
| datasets = filter_selected_options(datasets, columns, load_options) | |
| with st.sidebar.expander("Frequency"): | |
| load_options = get_frequency(datasets, columns, load_options) | |
| tmp_renaming_columns(datasets, columns, load_options) | |
| food_df = frequency_grouping(datasets["data"], load_options["freq"]) | |
| st.sidebar.title("2. Modelling") | |
| with st.sidebar.expander("Algorithm"): | |
| load_options["algorithm"] = st.selectbox("Select an algorithm:", ["Algorithm 1", "Algorithm 2", "Algorithm 3"]) | |
| st.sidebar.title("3. Forecast") | |
| load_options["evaluate"] = st.sidebar.checkbox("Evaluate model", value=True) | |
| if load_options["evaluate"]: | |
| with st.sidebar.expander("Split dates", expanded=True): | |
| dates = get_dates(food_df) | |
| datasets["train_df"], datasets["test_df"] = split_dataset(food_df, dates) | |
| load_options["forecast"] = st.sidebar.checkbox("Forecast model") | |
| if load_options["forecast"]: | |
| with st.sidebar.expander("Duration", expanded= True): | |
| food_df, load_options = get_forecast_dates(food_df, load_options) | |
| # check enough rows | |
| valid_rows_number(food_df, datasets, load_options) | |
| st.sidebar.button("Run", on_click=click_button) | |
| # run forecast if button is clicked | |
| if st.session_state.clicked: | |
| results = forecast_models(food_df, datasets, load_options) | |
| #visualizing the dataset | |
| st.header("1. Visualizing data") | |
| visualise_data(food_df, datasets, load_options) | |
| #training the data | |
| if load_options["evaluate"]: | |
| st.header("2. Evaluation") | |
| st.subheader("Overview") | |
| visualise_evaluation(results, load_options) | |
| st.subheader("Global performance") | |
| display_evaluation(results) | |
| if load_options["forecast"]: | |
| st.header("3. Forecast" if load_options['evaluate'] else "2. Forecast") | |
| visualise_forecast(results, load_options) | |
| # CSS to inject contained in a string | |
| hide_table_row_index = """ | |
| <style> | |
| thead tr th:first-child {display:none} | |
| tbody th {display:none} | |
| </style> | |
| """ | |
| # Inject CSS with Markdown | |
| st.markdown(hide_table_row_index, unsafe_allow_html=True) | |
| if __name__ == '__main__': | |
| main() | |