Spaces:
Sleeping
Sleeping
Add app
Browse files- Dockerfile +36 -0
- app.py +91 -0
Dockerfile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Start with a lightweight Linux Anaconda image
|
| 2 |
+
FROM continuumio/miniconda3
|
| 3 |
+
|
| 4 |
+
# Update all packages and install nano unzip and curl
|
| 5 |
+
RUN apt-get update
|
| 6 |
+
RUN apt-get install nano unzip curl -y
|
| 7 |
+
|
| 8 |
+
# THIS IS SPECIFIC TO HUGGINFACE
|
| 9 |
+
# We create a new user named "user" with ID of 1000
|
| 10 |
+
RUN useradd -m -u 1000 user
|
| 11 |
+
# We switch from "root" (default user when creating an image) to "user"
|
| 12 |
+
USER user
|
| 13 |
+
# We set two environment variables
|
| 14 |
+
# so that we can give ownership to all files in there afterwards
|
| 15 |
+
# we also add /home/user/.local/bin in the $PATH environment variable
|
| 16 |
+
# PATH environment variable sets paths to look for installed binaries
|
| 17 |
+
# We update it so that Linux knows where to look for binaries if we were to install them with "user".
|
| 18 |
+
ENV HOME=/home/user \
|
| 19 |
+
PATH=/home/user/.local/bin:$PATH
|
| 20 |
+
|
| 21 |
+
# We set working directory to $HOME/app (<=> /home/user/app)
|
| 22 |
+
WORKDIR $HOME/app
|
| 23 |
+
|
| 24 |
+
# Install basic dependencies
|
| 25 |
+
RUN pip install boto3 pandas gunicorn streamlit scikit-learn matplotlib seaborn plotly
|
| 26 |
+
|
| 27 |
+
# Copy all local files to /home/user/app with "user" as owner of these files
|
| 28 |
+
# Always use --chown=user when using HUGGINGFACE to avoid permission errors
|
| 29 |
+
COPY --chown=user . $HOME/app
|
| 30 |
+
|
| 31 |
+
# THIS IS SPECIFIC TO HUGGINGFACE AS WELL
|
| 32 |
+
# expose port 7860 which is the port used by HuggingFace for Web Applications
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
|
| 35 |
+
# Run streamlit server
|
| 36 |
+
CMD streamlit run --server.port 7860 app.py
|
app.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
import plotly.graph_objects as go
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
### CONFIG
|
| 9 |
+
st.set_page_config(
|
| 10 |
+
page_title="E-commerce",
|
| 11 |
+
page_icon="💸",
|
| 12 |
+
layout="wide"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
### TITLE AND TEXT
|
| 16 |
+
st.title("Sport Heroes")
|
| 17 |
+
st.image("https://stillmed.olympic.org/media/Images/OlympicOrg/IOC/The_Organisation/The-Olympic-Rings/Olympic_rings_TM_c_IOC_All_rights_reserved_1.jpg", width=300)
|
| 18 |
+
|
| 19 |
+
### EXPANDER
|
| 20 |
+
st.subheader("Opening French Olympic Games")
|
| 21 |
+
with st.expander("⏯️ Watch "):
|
| 22 |
+
st.video("https://youtu.be/6ldC6uHxHIc?si=94yBjIq41YakFQ1C")
|
| 23 |
+
|
| 24 |
+
st.subheader("The Raw Data")
|
| 25 |
+
st.markdown("""
|
| 26 |
+
All the __Heroes__ are in this Raw Datas 👇
|
| 27 |
+
""")
|
| 28 |
+
|
| 29 |
+
### LOAD AND CACHE DATA
|
| 30 |
+
DATA_URL = ('athlete_events.csv')
|
| 31 |
+
|
| 32 |
+
@st.cache_data # this lets the
|
| 33 |
+
def load_data(nrows):
|
| 34 |
+
data = pd.read_csv(DATA_URL, nrows=nrows)
|
| 35 |
+
return data
|
| 36 |
+
|
| 37 |
+
data_load_state = st.text('Loading data...')
|
| 38 |
+
data = load_data(1000)
|
| 39 |
+
data_load_state.text("") # change text from "Loading data..." to "" once the the load_data function has run
|
| 40 |
+
|
| 41 |
+
## Run the below code if the check is checked ✅
|
| 42 |
+
if st.checkbox('Show raw data'):
|
| 43 |
+
st.subheader('Raw data')
|
| 44 |
+
st.write(data)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
### SHOW GRAPH STREAMLIT
|
| 48 |
+
|
| 49 |
+
st.subheader("Medals per Country")
|
| 50 |
+
medal_per_country = data.groupby("NOC")["Medal"].describe() # Fix bar chart issue
|
| 51 |
+
st.bar_chart(medal_per_country)
|
| 52 |
+
|
| 53 |
+
### SHOW GRAPH PLOTLY + STREAMLIT
|
| 54 |
+
|
| 55 |
+
st.subheader("All the Olympic Countries X events")
|
| 56 |
+
|
| 57 |
+
fig = px.histogram(data, x="Year", color='City', barmode="group")
|
| 58 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
### SIDEBAR
|
| 62 |
+
st.sidebar.header("Build dashboards with Streamlit")
|
| 63 |
+
st.sidebar.markdown("""
|
| 64 |
+
* [Opening French Olympic Games](#opening-french-olympic-games)
|
| 65 |
+
* [Sport Heros Top](#sport-heroes)
|
| 66 |
+
* [Medals per Country](#medals-per-country)
|
| 67 |
+
* [Input Data](#input-data)
|
| 68 |
+
""")
|
| 69 |
+
e = st.sidebar.empty()
|
| 70 |
+
e.write("")
|
| 71 |
+
st.sidebar.write("Made with 💖 by [Jedha](https://jedha.co)")
|
| 72 |
+
st.sidebar.image("Leon-Marchand.png")
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
st.markdown("---")
|
| 77 |
+
|
| 78 |
+
#### CREATE TWO COLUMNS
|
| 79 |
+
|
| 80 |
+
@st.cache_data # this lets the
|
| 81 |
+
def load_datam():
|
| 82 |
+
datam = pd.read_csv(DATA_URL)
|
| 83 |
+
return datam
|
| 84 |
+
datam = load_datam()
|
| 85 |
+
st.markdown("**1️⃣ Example of input widget**")
|
| 86 |
+
country = st.selectbox("Select a country you want to see all the medals", datam["NOC"].sort_values().unique())
|
| 87 |
+
country_medal = datam[datam["NOC"]==country].groupby('Medal')['Sex'].value_counts().reset_index()
|
| 88 |
+
fig = px.bar(country_medal, x='Medal', y='count', color='Sex', barmode='group')
|
| 89 |
+
fig.update_layout(bargap=0.2)
|
| 90 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 91 |
+
|