Spaces:
Sleeping
Sleeping
Fix: Added safety checks for secrets and updated UI
Browse files- src/streamlit_app.py +16 -6
src/streamlit_app.py
CHANGED
|
@@ -57,16 +57,26 @@ st.markdown("""
|
|
| 57 |
""", unsafe_allow_html=True)
|
| 58 |
|
| 59 |
# --- CLOUD DATA LOGGING (GOOGLE SHEETS) ---
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
else:
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
def save_to_cloud(text, ai_label, ai_score, corrected_label=None):
|
| 67 |
try:
|
| 68 |
-
|
| 69 |
-
# Using "Sheet1" as per your previous spreadsheet setup
|
| 70 |
existing_data = conn.read(spreadsheet=sheet_url, worksheet="Sheet1", ttl=0)
|
| 71 |
except:
|
| 72 |
existing_data = pd.DataFrame()
|
|
|
|
| 57 |
""", unsafe_allow_html=True)
|
| 58 |
|
| 59 |
# --- CLOUD DATA LOGGING (GOOGLE SHEETS) ---
|
| 60 |
+
# Use .get() to prevent the "StreamlitSecretNotFoundError" crash
|
| 61 |
+
gsheets_json = st.secrets.get("GSHEETS_JSON")
|
| 62 |
+
sheet_url = st.secrets.get("GSHEETS_URL")
|
| 63 |
+
|
| 64 |
+
if gsheets_json and sheet_url:
|
| 65 |
+
try:
|
| 66 |
+
creds = json.loads(gsheets_json)
|
| 67 |
+
conn = st.connection("gsheets", type=GSheetsConnection, credentials=creds)
|
| 68 |
+
except Exception as e:
|
| 69 |
+
st.error(f"Configuration Error: {e}")
|
| 70 |
+
st.stop()
|
| 71 |
else:
|
| 72 |
+
# This replaces the red crash box with a clean instructions message
|
| 73 |
+
st.warning("🚀 System Initializing... Please ensure GSHEETS_JSON and GSHEETS_URL are set in Hugging Face Settings.")
|
| 74 |
+
st.info("If you just added them, please wait 30 seconds and refresh.")
|
| 75 |
+
st.stop()
|
| 76 |
|
| 77 |
def save_to_cloud(text, ai_label, ai_score, corrected_label=None):
|
| 78 |
try:
|
| 79 |
+
# Pull fresh data to append to
|
|
|
|
| 80 |
existing_data = conn.read(spreadsheet=sheet_url, worksheet="Sheet1", ttl=0)
|
| 81 |
except:
|
| 82 |
existing_data = pd.DataFrame()
|