File size: 1,302 Bytes
96f0aad
2790bac
96f0aad
 
96a7efe
037b17d
 
96a7efe
037b17d
2790bac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8243d0b
 
 
96f0aad
8243d0b
 
96f0aad
8243d0b
 
96f0aad
8243d0b
 
96f0aad
8243d0b
 
 
 
 
 
96a7efe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st
import pandas as pd

# Set the title of the app
st.title("App with Form and File Upload")

# Display an image
st.image("./nadi-lok-image.png")

# Sidebar for file upload
st.sidebar.header("Upload CSV File")
uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type="csv")

# Display the uploaded file's content if a file is uploaded
if uploaded_file:
    # Read the CSV file
    try:
        data = pd.read_csv(uploaded_file)
        st.sidebar.success("File uploaded successfully!")
        st.sidebar.write("Preview of the uploaded file:")
        st.sidebar.dataframe(data.head())  # Display the first few rows of the data
    except Exception as e:
        st.sidebar.error(f"Error reading file: {e}")

# Main app - Create a form
with st.form("user_form"):
    # Display a header
    st.header("Welcome to Streamlit Form!")

    # Add a text input widget
    user_input = st.text_input("Enter your name:")

    # Add a slider widget
    age = st.slider("Select your age:", 0, 100, 25)

    # Add form buttons
    submit_button = st.form_submit_button("Submit")

# Handle form submission
if submit_button:
    if user_input:
        st.success(f"Hello, {user_input}!")
        st.info(f"You are {age} years old.")
    else:
        st.error("Please enter your name.")