Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +29 -15
src/streamlit_app.py
CHANGED
|
@@ -3,27 +3,39 @@ import requests
|
|
| 3 |
import streamlit_authenticator as stauth
|
| 4 |
import datetime
|
| 5 |
|
| 6 |
-
#
|
| 7 |
credentials = {
|
| 8 |
"usernames": {
|
| 9 |
"admin": {
|
| 10 |
"name": "Admin",
|
| 11 |
-
"password": "12345" # Replace with hashed password for
|
| 12 |
}
|
| 13 |
}
|
| 14 |
}
|
| 15 |
|
| 16 |
-
authenticator = stauth.Authenticate(
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
if auth_status is False:
|
| 20 |
-
st.error("Incorrect username
|
| 21 |
elif auth_status is None:
|
| 22 |
-
st.warning("
|
| 23 |
elif auth_status:
|
| 24 |
authenticator.logout("Logout", "sidebar")
|
| 25 |
|
| 26 |
-
st.title("Boiler Production Tracking")
|
| 27 |
|
| 28 |
with st.form("entry_form"):
|
| 29 |
customer_name = st.text_input("CUSTOMER NAME")
|
|
@@ -64,10 +76,10 @@ elif auth_status:
|
|
| 64 |
|
| 65 |
remark = st.text_area("REMARK")
|
| 66 |
|
| 67 |
-
submitted = st.form_submit_button("Submit Data")
|
| 68 |
|
| 69 |
if submitted:
|
| 70 |
-
url = "
|
| 71 |
|
| 72 |
payload = {
|
| 73 |
"customer_name": customer_name,
|
|
@@ -105,9 +117,11 @@ elif auth_status:
|
|
| 105 |
"remark": remark
|
| 106 |
}
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
| 3 |
import streamlit_authenticator as stauth
|
| 4 |
import datetime
|
| 5 |
|
| 6 |
+
# ========================= LOGIN SETUP =========================
|
| 7 |
credentials = {
|
| 8 |
"usernames": {
|
| 9 |
"admin": {
|
| 10 |
"name": "Admin",
|
| 11 |
+
"password": "12345" # Replace with hashed password for real use
|
| 12 |
}
|
| 13 |
}
|
| 14 |
}
|
| 15 |
|
| 16 |
+
authenticator = stauth.Authenticate(
|
| 17 |
+
credentials,
|
| 18 |
+
"app_home",
|
| 19 |
+
"abcdef",
|
| 20 |
+
cookie_expiry_days=1
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
fields = {
|
| 24 |
+
"Form name": "Login",
|
| 25 |
+
"Username": "Enter username",
|
| 26 |
+
"Password": "Enter password"
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
name, auth_status, username = authenticator.login(fields=fields, location="main")
|
| 30 |
|
| 31 |
if auth_status is False:
|
| 32 |
+
st.error("β Incorrect username or password")
|
| 33 |
elif auth_status is None:
|
| 34 |
+
st.warning("π Please enter your credentials")
|
| 35 |
elif auth_status:
|
| 36 |
authenticator.logout("Logout", "sidebar")
|
| 37 |
|
| 38 |
+
st.title("π Boiler Production Tracking Form")
|
| 39 |
|
| 40 |
with st.form("entry_form"):
|
| 41 |
customer_name = st.text_input("CUSTOMER NAME")
|
|
|
|
| 76 |
|
| 77 |
remark = st.text_area("REMARK")
|
| 78 |
|
| 79 |
+
submitted = st.form_submit_button("π₯ Submit Data")
|
| 80 |
|
| 81 |
if submitted:
|
| 82 |
+
url = "YOUR_GOOGLE_APPS_SCRIPT_WEB_APP_URL" # Replace with your deployed Apps Script URL
|
| 83 |
|
| 84 |
payload = {
|
| 85 |
"customer_name": customer_name,
|
|
|
|
| 117 |
"remark": remark
|
| 118 |
}
|
| 119 |
|
| 120 |
+
try:
|
| 121 |
+
r = requests.post(url, json=payload)
|
| 122 |
+
if r.status_code == 200:
|
| 123 |
+
st.success("β
Data successfully added to Google Sheet!")
|
| 124 |
+
else:
|
| 125 |
+
st.error(f"β Failed to send data. Status: {r.status_code}")
|
| 126 |
+
except Exception as e:
|
| 127 |
+
st.error(f"β Error sending data: {e}")
|