Spaces:
Running
Running
James McCool
Add initial Streamlit app structure with data loading and portfolio management tabs
8c22e49
import streamlit as st | |
st.set_page_config(layout="wide") | |
import numpy as np | |
import pandas as pd | |
import time | |
from fuzzywuzzy import process | |
def load_file(upload): | |
if upload is not None: | |
try: | |
if upload.name.endswith('.csv'): | |
df = pd.read_csv(upload) | |
elif upload.name.endswith(('.xls', '.xlsx')): | |
df = pd.read_excel(upload) | |
else: | |
st.error('Please upload either a CSV or Excel file') | |
return None | |
export_df = df.copy() | |
return export_df, df | |
except Exception as e: | |
st.error(f'Error loading file: {str(e)}') | |
return None | |
return None | |
tab1, tab2 = st.tabs(["Data Load", "Manage Portfolio"]) | |
with tab1: | |
if st.button('Clear data', key='reset1'): | |
st.session_state.clear() | |
st.subheader("Projections File") | |
st.info("upload a projections file that has Data oriented in the following format:") | |
# Create two columns for the uploader and template button | |
upload_col, template_col = st.columns([3, 1]) | |
with upload_col: | |
projections_file = st.file_uploader("Upload Projections File (CSV or Excel)", type=['csv', 'xlsx', 'xls']) | |
with template_col: | |
# Create empty DataFrame with required columns | |
template_df = pd.DataFrame(columns=['player_names', 'position', 'team', 'salary', 'median', 'ownership', 'captain ownership']) | |
# Add download button for template | |
st.download_button( | |
label="Template", | |
data=template_df.to_csv(index=False), | |
file_name="projections_template.csv", | |
mime="text/csv" | |
) | |
if projections_file: | |
export_projections, projections = load_file(projections_file) | |
if projections is not None: | |
st.success('Projections file loaded successfully!') | |
st.dataframe(projections) | |
with tab2: | |
if st.button('Clear data', key='reset2'): | |
st.session_state.clear() |