Spaces:
Runtime error
Runtime error
Download functions.py from Silverxwolf/FoodQast: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/Silverxwolf/FoodQast/resolve/main/functions.py
- Command line
-
hf download hf://spaces/Silverxwolf/FoodQast/functions.py
-
curl -L -o functions.py https://huggingface.co/spaces/Silverxwolf/FoodQast/resolve/main/functions.py
1.81 kB
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import streamlit_authenticator as stauth | |
| import yaml | |
| from yaml.loader import SafeLoader | |
| def frequency_grouping(df, freq): | |
| # group according to frequency | |
| df.set_index('date', inplace=True) | |
| df = df.resample(freq).sum() | |
| df.reset_index('date', inplace=True) | |
| # Replace small values with 0.01 | |
| df.loc[df["food_amount"] < 0.01, "food_amount"] = 0.01 | |
| return df | |
| def click_button(): | |
| st.session_state.clicked = True | |
| def auth_form(config): | |
| authenticator = stauth.Authenticate( | |
| config['credentials'], | |
| config['cookie']['name'], | |
| config['cookie']['key'], | |
| config['cookie']['expiry_days'], | |
| config['preauthorized'] | |
| ) | |
| _, authentication_status, username = authenticator.login('Login', 'main') | |
| return authentication_status, username, authenticator | |
| def load_config_file(file): | |
| with open(file) as file: | |
| config = yaml.load(file, Loader=SafeLoader) | |
| return config | |
| def upload_files(): | |
| two_files = st.sidebar.checkbox("Recipe and sales on seperate files") | |
| file = st.sidebar.file_uploader('Upload sales file', type=["csv", "xlsx", " xls"]) | |
| recipe_file = True | |
| if two_files: | |
| recipe_file = st.sidebar.file_uploader('Upload recipe file', type=["csv", "xlsx", " xls"]) | |
| return file, recipe_file, two_files | |
| def check_upload_status(file, recipe_file): | |
| if ('clicked' not in st.session_state) or (not file) or (not recipe_file): | |
| st.session_state.clicked = False | |
| # Remove items that are sold less than 70% of total days | |
| #TODO: filter invalid items | |
| # Select item to forecast if there is items column |