streamlit-1.25 / app.py
whitphx's picture
whitphx HF Staff
Create app.py
7f73f8c
raw
history blame
2.12 kB
from datetime import datetime, time
import streamlit as st
import numpy as np
st.title("Streamlit App at Hugging Face Spaces!")
st.image("https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo-with-title.png")
with st.form("my_form"):
st.write("Inside the form")
slider_val = st.slider("Form slider")
checkbox_val = st.checkbox("Form checkbox")
# Every form must have a submit button.
submitted = st.form_submit_button("Submit")
if submitted:
st.write("slider", slider_val, "checkbox", checkbox_val)
col1, col2, col3 = st.columns(3)
with col1:
st.image("https://static.streamlit.io/examples/cat.jpg")
with col2:
st.image("https://static.streamlit.io/examples/dog.jpg")
with col3:
st.image("https://static.streamlit.io/examples/owl.jpg")
with st.sidebar:
# st.image("https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.png")
st.image("https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo-with-title.png")
values = st.slider(
'Select a range of values',
0.0, 100.0, (25.0, 75.0))
st.write('Values:', values)
appointment = st.slider(
"Schedule your appointment:",
value=(time(11, 30), time(12, 45)))
st.write("You're scheduled for:", appointment)
start_time = st.slider(
"When do you start?",
value=datetime(2020, 1, 1, 9, 30),
format="MM/DD/YY - hh:mm")
st.write("Start time:", start_time)
if "chat_messages" not in st.session_state:
st.session_state.chat_messages = []
prompt = st.chat_input("Say something")
if prompt:
st.session_state.chat_messages.append({"type": "user", "message": prompt})
st.session_state.chat_messages.append({"type": "bot", "message": "Hello!", "chart": np.random.randn(30, 3)})
for message in st.session_state.chat_messages[::-1]:
if message["type"] == "user":
with st.chat_message("You"):
st.write(message["message"])
else:
with st.chat_message("Bot"):
st.write(message["message"])
st.line_chart(message["chart"])