pratikshahp commited on
Commit
8243d0b
·
verified ·
1 Parent(s): f271975

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
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
- # Display a header
7
- st.header("Welcome to Streamlit!")
 
 
8
 
9
- # Add a text input widget
10
- user_input = st.text_input("Enter your name:")
11
 
12
- # Display the user's input
13
- if user_input:
14
- st.write(f"Hello, {user_input}!")
15
 
16
- # Add a slider widget
17
- age = st.slider("Select your age:", 0, 100, 25)
 
18
 
19
- # Display the selected age
20
- st.write(f"You are {age} years old.")
 
 
 
 
 
21
 
22
- # Add an image
 
 
 
 
 
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")