jordancaraballo commited on
Commit
9c03e16
·
1 Parent(s): 6b39908

Deploying app

Browse files
Files changed (2) hide show
  1. requirements.txt +2 -1
  2. src/streamlit_app.py +79 -67
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  altair
2
  pandas
3
  streamlit
4
- matplotlib
 
 
1
  altair
2
  pandas
3
  streamlit
4
+ matplotlib
5
+ faker
src/streamlit_app.py CHANGED
@@ -1,73 +1,85 @@
1
- import pandas as pd
2
  import streamlit as st
 
 
3
 
4
- # Title
5
- st.title('Hello, Streamlit!')
6
-
7
- # Header
8
- st.header('This is a header')
9
-
10
- # Subheader
11
- st.subheader('This is a subheader')
12
-
13
- # Text
14
- st.text('Hello, this is a simple text.')
15
-
16
- # Markdown
17
- st.markdown('**This is markdown text**')
18
-
19
- # Display Data
20
- st.write('This is a simple write command.')
21
- st.write({'key': 'value', 'key2': 'value2'})
22
-
23
- # Widgets
24
- name = st.text_input('Enter your name:')
25
- st.write('Hello,', name)
26
-
27
- age = st.slider('Select your age:', 0, 100, 25)
28
- st.write('Your age is:', age)
29
-
30
-
31
- # Create a DataFrame
32
- df = pd.DataFrame({
33
- 'Column 1': [1, 2, 3, 4],
34
- 'Column 2': [10, 20, 30, 40]
35
- })
36
-
37
- # Display DataFrame
38
- st.dataframe(df)
39
-
40
- import matplotlib.pyplot as plt
41
- import numpy as np
42
-
43
- # Generate data
44
- x = np.linspace(0, 10, 100)
45
- y = np.sin(x)
46
-
47
- # Create a plot
48
- fig, ax = plt.subplots()
49
- ax.plot(x, y)
50
-
51
- # Display the plot
52
- st.pyplot(fig)
53
-
54
- # Button
55
- if st.button('Click me'):
56
- st.write('Button clicked!')
57
 
58
- # Checkbox
59
- agree = st.checkbox('I agree')
60
- if agree:
61
- st.write('Great!')
 
 
 
 
 
 
62
 
63
- # Radio buttons
64
- option = st.radio('Choose one:', ['Option 1', 'Option 2', 'Option 3'])
65
- st.write('You selected:', option)
66
 
67
- # Selectbox
68
- select = st.selectbox('Select a number:', [1, 2, 3, 4])
69
- st.write('You selected:', select)
70
 
71
- # Multiselect
72
- multi_select = st.multiselect('Select multiple options:', [1, 2, 3, 4])
73
- st.write('You selected:', multi_select)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ from faker import Faker
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ # Generate dummy data function
7
+ def generate_dummy_data(n=20):
8
+ fake = Faker()
9
+ data = [{
10
+ "First Name": fake.first_name(),
11
+ "Last Name": fake.last_name(),
12
+ "Phone Number": fake.phone_number(),
13
+ "Address": fake.address().replace('\n', ', ')
14
+ } for _ in range(n)]
15
+ return pd.DataFrame(data)
16
 
 
 
 
17
 
18
+ # Initialize session state
19
+ if 'df' not in st.session_state:
20
+ st.session_state.df = generate_dummy_data()
21
 
22
+ # Title
23
+ st.title("Customer CRM App")
24
+
25
+ # Menu
26
+ option = st.sidebar.radio("Select Action", ["Add", "Delete", "Update", "Search", "View", "Upload CSV"])
27
+
28
+ # Add customer
29
+ if option == "Add":
30
+ st.subheader("Add a new customer")
31
+ first = st.text_input("First Name")
32
+ last = st.text_input("Last Name")
33
+ phone = st.text_input("Phone Number")
34
+ address = st.text_input("Address")
35
+ if st.button("Add Customer"):
36
+ st.session_state.df.loc[len(st.session_state.df)] = [first, last, phone, address]
37
+ st.success("Customer added!")
38
+
39
+ # Delete customer
40
+ elif option == "Delete":
41
+ st.subheader("Delete a customer by index")
42
+ if len(st.session_state.df) > 0:
43
+ idx = st.number_input("Enter index", min_value=0, max_value=len(st.session_state.df)-1, step=1)
44
+ if st.button("Delete"):
45
+ st.session_state.df.drop(index=idx, inplace=True)
46
+ st.session_state.df.reset_index(drop=True, inplace=True)
47
+ st.success("Customer deleted!")
48
+ else:
49
+ st.warning("No customers to delete.")
50
+
51
+ # Update customer
52
+ elif option == "Update":
53
+ st.subheader("Update customer by index")
54
+ if len(st.session_state.df) > 0:
55
+ idx = st.number_input("Customer index to update", min_value=0, max_value=len(st.session_state.df)-1, step=1)
56
+ first = st.text_input("First Name", value=st.session_state.df.at[idx, "First Name"])
57
+ last = st.text_input("Last Name", value=st.session_state.df.at[idx, "Last Name"])
58
+ phone = st.text_input("Phone Number", value=st.session_state.df.at[idx, "Phone Number"])
59
+ address = st.text_input("Address", value=st.session_state.df.at[idx, "Address"])
60
+ if st.button("Update"):
61
+ st.session_state.df.loc[idx] = [first, last, phone, address]
62
+ st.success("Customer updated!")
63
+ else:
64
+ st.warning("No customers to update.")
65
+
66
+ # Search
67
+ elif option == "Search":
68
+ st.subheader("Search by First Name")
69
+ query = st.text_input("Enter first name")
70
+ if st.button("Search"):
71
+ result = st.session_state.df[st.session_state.df["First Name"].str.contains(query, case=False)]
72
+ st.write(result)
73
+
74
+ # View all
75
+ elif option == "View":
76
+ st.subheader("All Customers")
77
+ st.dataframe(st.session_state.df)
78
+
79
+ # Upload CSV
80
+ elif option == "Upload CSV":
81
+ st.subheader("Upload Dummy CSV")
82
+ uploaded_file = st.file_uploader("Choose a CSV", type="csv")
83
+ if uploaded_file is not None:
84
+ st.session_state.df = pd.read_csv(uploaded_file)
85
+ st.success("Database loaded from uploaded CSV!")