joycecast commited on
Commit
e934b8c
·
verified ·
1 Parent(s): 204120e

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +33 -1
  2. app.py +54 -0
README.md CHANGED
@@ -77,6 +77,37 @@ Upload Excel file with these columns:
77
  5. **Export Selection**: Manage export cache and download Excel reports
78
  6. **HTS Reference**: View Steel/Aluminum/Copper HTS lists and overlaps
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  ## Local Development
81
 
82
  ```bash
@@ -94,7 +125,8 @@ streamlit run app.py
94
  - `hts_validator.py`
95
  - `HTS_list.py`
96
  - `requirements.txt`
97
- 4. The app will auto-deploy
 
98
 
99
  ## Files
100
 
 
77
  5. **Export Selection**: Manage export cache and download Excel reports
78
  6. **HTS Reference**: View Steel/Aluminum/Copper HTS lists and overlaps
79
 
80
+ ## Password Protection
81
+
82
+ The app requires password authentication. Configure it using one of these methods:
83
+
84
+ ### For Hugging Face Spaces
85
+
86
+ 1. Go to your Space's **Settings** > **Repository secrets**
87
+ 2. Add a secret named `APP_PASSWORD` with your password value
88
+ 3. The app will automatically use this for authentication
89
+
90
+ ### For Local Development
91
+
92
+ Set the environment variable before running:
93
+
94
+ ```bash
95
+ # Windows
96
+ set HTS_CHECKER_PASSWORD=your_password_here
97
+ streamlit run app.py
98
+
99
+ # Linux/Mac
100
+ export HTS_CHECKER_PASSWORD=your_password_here
101
+ streamlit run app.py
102
+ ```
103
+
104
+ Or create a `.streamlit/secrets.toml` file:
105
+ ```toml
106
+ APP_PASSWORD = "your_password_here"
107
+ ```
108
+
109
+ **Note**: If no password is configured, the app runs without authentication (for development).
110
+
111
  ## Local Development
112
 
113
  ```bash
 
125
  - `hts_validator.py`
126
  - `HTS_list.py`
127
  - `requirements.txt`
128
+ 4. Go to **Settings** > **Repository secrets** and add `APP_PASSWORD`
129
+ 5. The app will auto-deploy with password protection
130
 
131
  ## Files
132
 
app.py CHANGED
@@ -7,6 +7,7 @@ import streamlit as st
7
  import pandas as pd
8
  from io import BytesIO
9
  import hashlib
 
10
  from hts_validator import HTSValidator, validate_dataframe, SCENARIO_SUMMARIES
11
  from HTS_list import Steel_primary_HTS_list, Aluminum_primary_HTS_list, Copper_primary_HTS_list
12
 
@@ -19,6 +20,59 @@ st.set_page_config(
19
  )
20
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  @st.cache_data
23
  def load_and_validate_excel(file_content, file_name, keywords_hash):
24
  """Load Excel and run validation - cached to avoid re-running on filter changes"""
 
7
  import pandas as pd
8
  from io import BytesIO
9
  import hashlib
10
+ import os
11
  from hts_validator import HTSValidator, validate_dataframe, SCENARIO_SUMMARIES
12
  from HTS_list import Steel_primary_HTS_list, Aluminum_primary_HTS_list, Copper_primary_HTS_list
13
 
 
20
  )
21
 
22
 
23
+ # =============================================================================
24
+ # Authentication
25
+ # =============================================================================
26
+ def get_app_password():
27
+ """Get password from secrets or environment variable."""
28
+ # Try Streamlit secrets first (for Hugging Face Spaces)
29
+ try:
30
+ return st.secrets["APP_PASSWORD"]
31
+ except (KeyError, FileNotFoundError):
32
+ pass
33
+ # Fall back to environment variable
34
+ return os.environ.get("HTS_CHECKER_PASSWORD", "")
35
+
36
+
37
+ def check_password():
38
+ """Returns True if the user has entered the correct password."""
39
+ app_password = get_app_password()
40
+
41
+ # If no password is set, allow access (for local development)
42
+ if not app_password:
43
+ return True
44
+
45
+ # Initialize session state for authentication
46
+ if "authenticated" not in st.session_state:
47
+ st.session_state.authenticated = False
48
+
49
+ # If already authenticated, return True
50
+ if st.session_state.authenticated:
51
+ return True
52
+
53
+ # Show login form
54
+ st.markdown("## HTS Checker - Login Required")
55
+ st.markdown("Please enter the password to access this application.")
56
+
57
+ with st.form("login_form"):
58
+ password_input = st.text_input("Password", type="password", key="password_input")
59
+ submit_button = st.form_submit_button("Login")
60
+
61
+ if submit_button:
62
+ if password_input == app_password:
63
+ st.session_state.authenticated = True
64
+ st.rerun()
65
+ else:
66
+ st.error("Incorrect password. Please try again.")
67
+
68
+ return False
69
+
70
+
71
+ # Check authentication before showing main app
72
+ if not check_password():
73
+ st.stop()
74
+
75
+
76
  @st.cache_data
77
  def load_and_validate_excel(file_content, file_name, keywords_hash):
78
  """Load Excel and run validation - cached to avoid re-running on filter changes"""