Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,35 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
# Set the title of the app
|
| 4 |
-
st.title("Basic Streamlit App")
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
st.
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
# Add a text input widget
|
| 10 |
-
user_input = st.text_input("Enter your name:")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
st.write(f"Hello, {user_input}!")
|
| 15 |
|
| 16 |
-
# Add
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
st.image("./nadi-lok-image.png", caption="Image")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
# Set the title of the app
|
| 4 |
+
st.title("Basic Streamlit App with Form")
|
| 5 |
|
| 6 |
+
# Create a form
|
| 7 |
+
with st.form("user_form"):
|
| 8 |
+
# Display a header
|
| 9 |
+
st.header("Welcome to Streamlit Form!")
|
| 10 |
|
| 11 |
+
# Add a text input widget
|
| 12 |
+
user_input = st.text_input("Enter your name:")
|
| 13 |
|
| 14 |
+
# Add a slider widget
|
| 15 |
+
age = st.slider("Select your age:", 0, 100, 25)
|
|
|
|
| 16 |
|
| 17 |
+
# Add form buttons
|
| 18 |
+
submit_button = st.form_submit_button("Submit")
|
| 19 |
+
clear_button = st.form_submit_button("Clear")
|
| 20 |
|
| 21 |
+
# Handle form submission
|
| 22 |
+
if submit_button:
|
| 23 |
+
if user_input:
|
| 24 |
+
st.success(f"Hello, {user_input}!")
|
| 25 |
+
st.info(f"You are {age} years old.")
|
| 26 |
+
else:
|
| 27 |
+
st.error("Please enter your name.")
|
| 28 |
|
| 29 |
+
# Handle form clearing
|
| 30 |
+
if clear_button:
|
| 31 |
+
# Re-run the app to reset the form
|
| 32 |
+
st.experimental_rerun()
|
| 33 |
+
|
| 34 |
+
# Display an image
|
| 35 |
st.image("./nadi-lok-image.png", caption="Image")
|