-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
76 lines (65 loc) · 2.57 KB
/
streamlit_app.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import streamlit as st
from streamlit_gsheets import GSheetsConnection
import pandas as pd
# Display Title and Description
st.title("Vendor Management Portal")
st.markdown("Enter the details of the new vendor below.")
# Establishing a Google Sheets connection
conn = st.connection("gsheets", type=GSheetsConnection)
# Fetch existing vendors data
existing_data = conn.read(worksheet="Data", usecols=list(range(6)), ttl=5)
existing_data = existing_data.dropna(how="all")
# List of Business Types and Products
BUSINESS_TYPES = [
"Manufacturer",
"Distributor",
"Wholesaler",
"Retailer",
"Service Provider",
]
PRODUCTS = [
"Electronics",
"Apparel",
"Groceries",
"Software",
"Other",
]
# Onboarding New Vendor Form
with st.form(key="vendor_form"):
company_name = st.text_input(label="Company Name*")
business_type = st.selectbox("Business Type*", options=BUSINESS_TYPES, index=None)
products = st.multiselect("Products Offered", options=PRODUCTS)
years_in_business = st.slider("Years in Business", 0, 50, 5)
onboarding_date = st.date_input(label="Onboarding Date")
additional_info = st.text_area(label="Additional Notes")
# Mark mandatory fields
st.markdown("**required*")
submit_button = st.form_submit_button(label="Submit Vendor Details")
# If the submit button is pressed
if submit_button:
# Check if all mandatory fields are filled
if not company_name or not business_type:
st.warning("Ensure all mandatory fields are filled.")
st.stop()
elif existing_data["CompanyName"].str.contains(company_name).any():
st.warning("A vendor with this company name already exists.")
st.stop()
else:
# Create a new row of vendor data
vendor_data = pd.DataFrame(
[
{
"CompanyName": company_name,
"BusinessType": business_type,
"Products": ", ".join(products),
"YearsInBusiness": years_in_business,
"OnboardingDate": onboarding_date.strftime("%Y-%m-%d"),
"AdditionalInfo": additional_info,
}
]
)
# Add the new vendor data to the existing data
updated_df = pd.concat([existing_data, vendor_data], ignore_index=True)
# Update Google Sheets with the new vendor data
conn.update(worksheet="Data", data=updated_df)
st.success("Vendor details successfully submitted!")