File size: 1,864 Bytes
5db4327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import os

OFFERS_FILE = "knowledge_base/received_offers.csv"

def show_admin_dashboard():
    st.subheader("🕵️‍♂️ Admin Console")
    
    # 1. Look for password in environment variables (.env locally or Secrets on Cloud)
    # It defaults to "ahan2026" if no variable is found
    correct_password = os.getenv("ADMIN_PASSWORD")
    
    # 2. UI for password entry
    admin_key = st.text_input("Enter Admin Password", type="password")
    
    if admin_key == correct_password:
        st.success("Access Granted")
        
        if os.path.exists(OFFERS_FILE):
            try:
                df = pd.read_csv(OFFERS_FILE)
                
                st.write("### Incoming Offers")
                # Summary Metrics
                c1, c2 = st.columns(2)
                c1.metric("Total Offers", len(df)+1)
                
                # Interactive Table
                st.dataframe(df, use_container_width=True)
                
                # Download Button
                csv = df.to_csv(index=False).encode('utf-8')
                st.download_button(
                    label="📥 Download Offers CSV",
                    data=csv,
                    file_name="ahan_bose_offers.csv",
                    mime="text/csv"
                )
                
                # Clear Data Button (with double confirmation)
                if st.checkbox("Enable Delete Mode"):
                    if st.button("🗑️ Permanent: Clear All Data"):
                        os.remove(OFFERS_FILE)
                        st.rerun()
            except Exception as e:
                st.error(f"Error reading offers: {e}")
        else:
            st.info("No offers in the database yet.")
            
    elif admin_key:
        st.error("Unauthorized access. Key does not match.")