Spaces:
Running
Running
James McCool
commited on
Commit
·
8c22e49
1
Parent(s):
e84cf1b
Add initial Streamlit app structure with data loading and portfolio management tabs
Browse files- app.py +60 -0
- app.yaml +10 -0
- requirements.txt +10 -0
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
st.set_page_config(layout="wide")
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
import time
|
6 |
+
from fuzzywuzzy import process
|
7 |
+
|
8 |
+
def load_file(upload):
|
9 |
+
if upload is not None:
|
10 |
+
try:
|
11 |
+
if upload.name.endswith('.csv'):
|
12 |
+
df = pd.read_csv(upload)
|
13 |
+
elif upload.name.endswith(('.xls', '.xlsx')):
|
14 |
+
df = pd.read_excel(upload)
|
15 |
+
else:
|
16 |
+
st.error('Please upload either a CSV or Excel file')
|
17 |
+
return None
|
18 |
+
|
19 |
+
export_df = df.copy()
|
20 |
+
|
21 |
+
return export_df, df
|
22 |
+
except Exception as e:
|
23 |
+
st.error(f'Error loading file: {str(e)}')
|
24 |
+
return None
|
25 |
+
return None
|
26 |
+
|
27 |
+
tab1, tab2 = st.tabs(["Data Load", "Manage Portfolio"])
|
28 |
+
with tab1:
|
29 |
+
if st.button('Clear data', key='reset1'):
|
30 |
+
st.session_state.clear()
|
31 |
+
|
32 |
+
st.subheader("Projections File")
|
33 |
+
st.info("upload a projections file that has Data oriented in the following format:")
|
34 |
+
|
35 |
+
# Create two columns for the uploader and template button
|
36 |
+
upload_col, template_col = st.columns([3, 1])
|
37 |
+
|
38 |
+
with upload_col:
|
39 |
+
projections_file = st.file_uploader("Upload Projections File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
|
40 |
+
|
41 |
+
with template_col:
|
42 |
+
# Create empty DataFrame with required columns
|
43 |
+
template_df = pd.DataFrame(columns=['player_names', 'position', 'team', 'salary', 'median', 'ownership', 'captain ownership'])
|
44 |
+
# Add download button for template
|
45 |
+
st.download_button(
|
46 |
+
label="Template",
|
47 |
+
data=template_df.to_csv(index=False),
|
48 |
+
file_name="projections_template.csv",
|
49 |
+
mime="text/csv"
|
50 |
+
)
|
51 |
+
|
52 |
+
if projections_file:
|
53 |
+
export_projections, projections = load_file(projections_file)
|
54 |
+
if projections is not None:
|
55 |
+
st.success('Projections file loaded successfully!')
|
56 |
+
st.dataframe(projections)
|
57 |
+
|
58 |
+
with tab2:
|
59 |
+
if st.button('Clear data', key='reset2'):
|
60 |
+
st.session_state.clear()
|
app.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
runtime: python
|
2 |
+
env: flex
|
3 |
+
|
4 |
+
runtime_config:
|
5 |
+
python_version: 3
|
6 |
+
|
7 |
+
entrypoint: streamlit run streamlit-app.py --server.port $PORT
|
8 |
+
|
9 |
+
automatic_scaling:
|
10 |
+
max_num_instances: 200
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
gspread
|
3 |
+
openpyxl
|
4 |
+
matplotlib
|
5 |
+
streamlit-aggrid
|
6 |
+
pulp
|
7 |
+
docker
|
8 |
+
plotly
|
9 |
+
scipy
|
10 |
+
pymongo
|