Refat81 commited on
Commit
8ecd1b3
Β·
verified Β·
1 Parent(s): 98692de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -89
app.py CHANGED
@@ -1,32 +1,6 @@
1
- # app.py - USING INDIVIDUAL SECRETS
2
  import streamlit as st
3
  import os
4
- import sys
5
-
6
- # Debug info
7
- print("=== APP START ===", file=sys.stderr)
8
- print(f"All env vars: {list(os.environ.keys())}", file=sys.stderr)
9
-
10
- def get_secret(key, default=""):
11
- """Get secret from environment or Streamlit secrets"""
12
- # Try environment first (HuggingFace individual secrets)
13
- env_value = os.getenv(key)
14
- if env_value:
15
- return env_value
16
-
17
- # Try Streamlit secrets as fallback
18
- try:
19
- # For nested keys like google.client_id
20
- if '.' in key:
21
- parts = key.split('.')
22
- value = st.secrets
23
- for part in parts:
24
- value = value[part]
25
- return value
26
- else:
27
- return st.secrets[key]
28
- except:
29
- return default
30
 
31
  def main():
32
  st.set_page_config(
@@ -35,54 +9,61 @@ def main():
35
  layout="wide"
36
  )
37
 
38
- # Get all secrets
39
- client_id = get_secret("GOOGLE_CLIENT_ID")
40
- client_secret = get_secret("GOOGLE_CLIENT_SECRET")
41
- session_key = get_secret("SESSION_SECRET_KEY")
42
- hf_token = get_secret("HUGGINGFACE_TOKEN")
43
- admin_email = get_secret("ADMIN_EMAIL")
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- # Debug display (safe)
46
- st.sidebar.write("### πŸ”§ Debug Info")
47
- st.sidebar.write(f"Client ID loaded: {'βœ…' if client_id else '❌'}")
48
- st.sidebar.write(f"Session key: {'βœ…' if session_key else '❌'}")
49
 
50
- # Check if essential secrets are loaded
51
- if not client_id or client_id == "your-client-id.apps.googleusercontent.com":
52
- st.error("""
53
- ⚠️ **Google OAuth Not Configured**
54
-
55
- **Please add these secrets to HuggingFace:**
56
-
57
- 1. Go to Space Settings β†’ Repository Secrets
58
- 2. Add these individual secrets:
59
-
60
- | Secret Name | Value |
61
- |-------------|-------|
62
- | `GOOGLE_CLIENT_ID` | Your Google Client ID |
63
- | `GOOGLE_CLIENT_SECRET` | Your Google Client Secret |
64
- | `SESSION_SECRET_KEY` | `LXr9Q2v8bPp1Yt6zMk5w7x0aS3dFg4hJ7n8cV2bN5m8q9T1y3U6i0o` |
65
- | `HUGGINGFACE_TOKEN` | Your HuggingFace token |
66
-
67
- 3. Click "Save"
68
- 4. Restart the Space
69
- """)
70
  return
71
 
72
- # Show login page
73
  st.title("πŸ” Social Media Data Extractor")
74
- st.markdown("---")
75
  st.markdown("### Welcome! Please login to continue")
76
 
77
  # Create login URL
78
  redirect_uri = "https://refat81-social-media-data-extractor-chatbot.hf.space/oauth_callback"
79
- login_url = f"https://accounts.google.com/o/oauth2/v2/auth?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&scope=openid%20email%20profile&access_type=offline&prompt=consent"
80
 
81
- # Google login button
82
  st.markdown(f"""
83
  <a href="{login_url}">
84
  <div style="
85
- background: linear-gradient(135deg, #4285F4, #34A853);
86
  color: white;
87
  padding: 15px 30px;
88
  border-radius: 8px;
@@ -93,38 +74,12 @@ def main():
93
  text-align: center;
94
  margin: 30px 0;
95
  display: inline-block;
96
- box-shadow: 0 4px 15px rgba(66, 133, 244, 0.3);
97
- transition: all 0.3s ease;
98
- "
99
- onmouseover="this.style.transform='translateY(-2px)'; this.style.boxShadow='0 6px 20px rgba(66, 133, 244, 0.4)';"
100
- onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='0 4px 15px rgba(66, 133, 244, 0.3)';"
101
- >
102
  <img src="https://cdn-icons-png.flaticon.com/512/2991/2991148.png" width="24" height="24" style="vertical-align: middle; margin-right: 12px;">
103
  Sign in with Google
104
  </div>
105
  </a>
106
  """, unsafe_allow_html=True)
107
-
108
- # Instructions
109
- with st.expander("πŸ“‹ Setup Instructions", expanded=True):
110
- st.markdown(f"""
111
- **Secrets Status:**
112
- - Google Client ID: {'βœ… Loaded' if client_id and 'placeholder' not in client_id else '❌ Not configured'}
113
- - Session Key: {'βœ… Loaded' if session_key else '❌ Missing'}
114
-
115
- **Next Steps:**
116
- 1. Click "Sign in with Google" above
117
- 2. Login with your Google account
118
- 3. Grant permissions to the app
119
- 4. You'll be redirected back to the dashboard
120
-
121
- **Note:** First login may show "App not verified" warning.
122
- Click "Advanced" β†’ "Go to app" to continue.
123
- """)
124
-
125
- # Footer
126
- st.markdown("---")
127
- st.caption("Β© 2024 Social Media Data Extractor | Secure OAuth Authentication")
128
 
129
  if __name__ == "__main__":
130
  main()
 
1
+ # app.py - UPDATED VERSION
2
  import streamlit as st
3
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def main():
6
  st.set_page_config(
 
9
  layout="wide"
10
  )
11
 
12
+ # Check if user is already logged in
13
+ if "authenticated" in st.session_state and st.session_state.authenticated:
14
+ show_dashboard()
15
+ else:
16
+ show_login_page()
17
+
18
+ def show_dashboard():
19
+ """Show main dashboard after login"""
20
+ user = st.session_state.user_info
21
+
22
+ # Welcome message
23
+ st.title(f"πŸ‘‹ Welcome, {user.get('name', 'User')}!")
24
+ st.write(f"Email: {user.get('email')}")
25
+
26
+ # Your original dashboard content here
27
+ st.markdown("## πŸš€ Launch Extractors")
28
+
29
+ col1, col2, col3 = st.columns(3)
30
 
31
+ with col1:
32
+ if st.button("πŸ’Ό LinkedIn Extractor", use_container_width=True):
33
+ st.switch_page("pages/linkedin_extractor.py")
 
34
 
35
+ with col2:
36
+ if st.button("πŸ“˜ Facebook Extractor", use_container_width=True):
37
+ st.switch_page("pages/facebook_extractor.py")
38
+
39
+ with col3:
40
+ if st.button("πŸ”₯ Facebook Extractor 2.0", use_container_width=True):
41
+ st.switch_page("pages/facebook_extractor_pro.py")
42
+
43
+ # Logout button
44
+ if st.button("πŸšͺ Logout"):
45
+ st.session_state.clear()
46
+ st.rerun()
47
+
48
+ def show_login_page():
49
+ """Show login page"""
50
+ GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "")
51
+
52
+ if not GOOGLE_CLIENT_ID:
53
+ st.error("Google OAuth not configured")
 
54
  return
55
 
 
56
  st.title("πŸ” Social Media Data Extractor")
 
57
  st.markdown("### Welcome! Please login to continue")
58
 
59
  # Create login URL
60
  redirect_uri = "https://refat81-social-media-data-extractor-chatbot.hf.space/oauth_callback"
61
+ login_url = f"https://accounts.google.com/o/oauth2/v2/auth?client_id={GOOGLE_CLIENT_ID}&redirect_uri={redirect_uri}&response_type=code&scope=openid%20email%20profile&access_type=offline&prompt=consent"
62
 
 
63
  st.markdown(f"""
64
  <a href="{login_url}">
65
  <div style="
66
+ background-color: #4285F4;
67
  color: white;
68
  padding: 15px 30px;
69
  border-radius: 8px;
 
74
  text-align: center;
75
  margin: 30px 0;
76
  display: inline-block;
77
+ ">
 
 
 
 
 
78
  <img src="https://cdn-icons-png.flaticon.com/512/2991/2991148.png" width="24" height="24" style="vertical-align: middle; margin-right: 12px;">
79
  Sign in with Google
80
  </div>
81
  </a>
82
  """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  if __name__ == "__main__":
85
  main()