import streamlit as st
import numpy as np
import pandas as pd
import datetime
class WaterTracker:
def __init__(self):
self.goal = 5
if 'glasses' not in st.session_state:
st.session_state.glasses = 0
if 'date' not in st.session_state:
st.session_state.date = datetime.date.today()
def add_glass(self):
if st.session_state.glasses < self.goal:
st.session_state.glasses += 1
self.check_progress()
def reset(self):
st.session_state.glasses = 0
st.session_state.date = datetime.date.today()
def check_progress(self):
remaining = self.goal - st.session_state.glasses
if remaining > 0:
st.write(f"You need to drink {remaining} more glass(es) to reach your goal.")
else:
st.write("You've reached your goal for today!")
print("\x1b[1;92mStreamlit script running...\x1b[0m")
st.title("Daily Water Tracker")
tracker = WaterTracker()
st.write(f"Today's date: {st.session_state.date}")
st.write(f"Glasses of water drunk today: {st.session_state.glasses}")
if st.button("Add a glass of water"):
tracker.add_glass()
if st.button("Reset for new day"):
tracker.reset()
tracker.check_progress()
# Visualize progress
progress = st.session_state.glasses / tracker.goal
st.progress(progress)
# Display a fun message based on progress
if progress == 1:
st.balloons()
st.success("Congratulations! You've met your water intake goal for the day!")
elif progress >= 0.8:
st.info("Almost there! Keep it up!")
elif progress >= 0.5:
st.info("Halfway there! You're doing great!")
elif progress > 0:
st.info("Good start! Keep drinking water throughout the day.")
else:
st.info("Start your water intake for the day!")
st.markdown(
"""
Py.cafe is a platform that allows you to create, run, edit, and share Python applications directly in your browser. There's
no need for any installation; it works with just a single click.
And now, you can use Streamlit on py.cafe! Streamlit is a popular Python library for creating web applications with simple
Python scripts. You can create interactive web applications with just a few lines of code.
"""
)
st.header("Example components")
st.subheader("Text input")
name = st.text_input("Your name?")
st.write("Hello,", name or "world", "!")
st.subheader("Slider")
value = st.slider("Value?")
st.write("The slider value is", value)
st.subheader("Chart sample")
chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
st.area_chart(chart_data)
st.subheader("DataFrame sample")
df = pd.DataFrame(np.random.randn(50, 20), columns=("col %d" % i for i in range(20)))
st.dataframe(df) # Same as st.write(df)
st.subheader("Camera and image")
if st.checkbox("Show camera"):
picture = st.camera_input("Take a picture")
if picture:
st.image(picture)
st.markdown(
"""
### Useful links:
* [Streamlit official website](https://streamlit.io/)
* [Streamlit documentation](https://docs.streamlit.io/)
### Alternatives
Also take a look at [stlite](https://edit.share.stlite.net/), a similar platform that allows you to create, run, edit, and share Python applications directly in your browser.
Py.cafe runs an unmodified version of streamlit, compared to stlite which has some modifications to make it work in the browser.
### Community
* [Py.cafe Discord](https://discord.gg/RpwWnFV3Dv)
* [Streamlit community forum](https://discuss.streamlit.io/)
"""
)