Shivraj8615 commited on
Commit
83860b9
Β·
verified Β·
1 Parent(s): 3a20012

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # ---------------- LOGIN SETUP ----------------
7
  credentials = {
8
  "usernames": {
9
  "admin": {
10
  "name": "Admin",
11
- "password": "12345" # Replace with hashed password for security
12
  }
13
  }
14
  }
15
 
16
- authenticator = stauth.Authenticate(credentials, "app_home", "abcdef", cookie_expiry_days=1)
17
- name, auth_status, username = authenticator.login("Login", "main")
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  if auth_status is False:
20
- st.error("Incorrect username/password")
21
  elif auth_status is None:
22
- st.warning("Enter your credentials")
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 = "https://script.google.com/a/macros/forbesmarshall.com/s/AKfycbyPTwzYNsy8D2M27O8ZZ90G1UYHP1aPExA_FX7VLh3iQquOt16Cc14tF7-xp8SGd1bE/exec" # Replace with your deployment URL
71
 
72
  payload = {
73
  "customer_name": customer_name,
@@ -105,9 +117,11 @@ elif auth_status:
105
  "remark": remark
106
  }
107
 
108
- r = requests.post(url, json=payload)
109
-
110
- if r.status_code == 200:
111
- st.success("βœ… Data added to Google Sheet successfully!")
112
- else:
113
- st.error("❌ Failed to send data. Please check the script URL.")
 
 
 
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}")