Refat81 commited on
Commit
99cdd6b
Β·
verified Β·
1 Parent(s): ed5c544

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +213 -47
app.py CHANGED
@@ -1,69 +1,172 @@
1
- # app.py - UPDATED VERSION
2
  import streamlit as st
3
  import os
4
 
5
- def main():
6
- st.set_page_config(
7
- page_title="Social Media Data Extractor",
8
- page_icon="πŸ”",
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;
@@ -71,15 +174,78 @@ def show_login_page():
71
  cursor: pointer;
72
  font-size: 18px;
73
  font-weight: 600;
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()
 
1
+ # app.py - COMPLETE WORKING VERSION
2
  import streamlit as st
3
  import os
4
 
5
+ # ============================================
6
+ # COMPATIBILITY FUNCTIONS
7
+ # ============================================
8
+
9
+ def get_query_params():
10
+ """Get query params with backward compatibility"""
11
+ try:
12
+ # Try new method (Streamlit 1.28+)
13
+ return st.query_params
14
+ except AttributeError:
15
+ # Fallback to old method
16
+ return st.experimental_get_query_params()
17
+
18
+ def clear_query_params():
19
+ """Clear query params with backward compatibility"""
20
+ try:
21
+ st.query_params.clear()
22
+ except AttributeError:
23
+ st.experimental_set_query_params()
24
+
25
+ # ============================================
26
+ # MAIN DASHBOARD
27
+ # ============================================
28
 
29
  def show_dashboard():
30
+ """Show the main dashboard after login"""
31
  user = st.session_state.user_info
32
 
33
+ # Apply your original styling
34
+ st.markdown("""
35
+ <style>
36
+ .stApp { background-color: #0e1117; color: white; }
37
+ .main-header { background: linear-gradient(135deg, #1a2a6c, #b21f1f); color: white; padding: 2rem; border-radius: 10px; text-align: center; margin-bottom: 2rem; }
38
+ .platform-card { background-color: #262730; padding: 1.5rem; border-radius: 10px; border-left: 4px solid; margin: 1rem 0; height: 280px; }
39
+ .linkedin-card { border-left-color: #0077B5; }
40
+ .facebook-card { border-left-color: #1877F2; }
41
+ .facebook-pro-card { border-left-color: #FF6B35; }
42
+ .feature-list { margin: 1rem 0; padding-left: 1.5rem; flex-grow: 1; }
43
+ </style>
44
+ """, unsafe_allow_html=True)
45
+
46
+ # Header with user info
47
+ st.markdown(f"""
48
+ <div class="main-header">
49
+ <h1 style="margin:0;">πŸ” Social Media Data Extractor</h1>
50
+ <p style="margin:0; opacity: 0.9;">Welcome back, {user.get('name', 'User')}! πŸ‘‹</p>
51
+ </div>
52
+ """, unsafe_allow_html=True)
53
+
54
+ # Sidebar with user info and logout
55
+ with st.sidebar:
56
+ if user.get('picture'):
57
+ st.image(user.get('picture'), width=80)
58
+ else:
59
+ st.image("https://cdn-icons-png.flaticon.com/512/149/149071.png", width=80)
60
+
61
+ st.write(f"**πŸ‘€ {user.get('name', 'User')}**")
62
+ st.write(f"πŸ“§ {user.get('email', '')}")
63
+ st.markdown("---")
64
+
65
+ if st.button("πŸšͺ Logout", use_container_width=True):
66
+ st.session_state.clear()
67
+ st.rerun()
68
 
69
+ # Platform selection
70
  st.markdown("## πŸš€ Launch Extractors")
71
 
72
  col1, col2, col3 = st.columns(3)
73
 
74
  with col1:
75
+ st.markdown("""
76
+ <div class="platform-card linkedin-card">
77
+ <h3>πŸ’Ό LinkedIn Extractor</h3>
78
+ <ul class="feature-list">
79
+ <li>No login required</li>
80
+ <li>Profile, company, and post analysis</li>
81
+ <li>Quick data extraction</li>
82
+ <li>AI-powered insights</li>
83
+ <li>100% Free</li>
84
+ </ul>
85
+ </div>
86
+ """, unsafe_allow_html=True)
87
+
88
+ if st.button("πŸš€ Launch LinkedIn Extractor", key="linkedin_btn", use_container_width=True):
89
  st.switch_page("pages/linkedin_extractor.py")
90
+
91
  with col2:
92
+ st.markdown("""
93
+ <div class="platform-card facebook-card">
94
+ <h3>πŸ“˜ Facebook Extractor</h3>
95
+ <ul class="feature-list">
96
+ <li>Manual login required</li>
97
+ <li>Group post extraction</li>
98
+ <li>Works with private groups</li>
99
+ <li>AI conversation analysis</li>
100
+ <li>100% Free</li>
101
+ </ul>
102
+ </div>
103
+ """, unsafe_allow_html=True)
104
+
105
+ if st.button("πŸš€ Launch Facebook Extractor", key="facebook_btn", use_container_width=True):
106
  st.switch_page("pages/facebook_extractor.py")
107
 
108
  with col3:
109
+ st.markdown("""
110
+ <div class="platform-card facebook-pro-card">
111
+ <h3>πŸ”₯ Facebook Extractor 2.0</h3>
112
+ <ul class="feature-list">
113
+ <li>Enhanced Facebook data extraction</li>
114
+ <li>More powerful algorithms</li>
115
+ <li>Faster processing speed</li>
116
+ <li>Advanced AI analysis</li>
117
+ <li>100% Free</li>
118
+ </ul>
119
+ </div>
120
+ """, unsafe_allow_html=True)
121
+
122
+ if st.button("πŸš€ Launch Facebook Extractor 2.0", key="facebook_pro_btn", use_container_width=True):
123
  st.switch_page("pages/facebook_extractor_pro.py")
124
+
125
+ # Instructions
126
+ with st.expander("πŸ“‹ How to Use", expanded=True):
127
+ st.markdown(f"""
128
+ 1. **Click any extractor to launch**
129
+ 2. **For LinkedIn:** Enter any LinkedIn URL
130
+ 3. **For Facebook:** Public data extraction available
131
+ 4. **AI Analysis:** Chat with extracted data
132
+
133
+ **Note:** All extractors are 100% free and require no local setup.
134
+
135
+ **Logged in as:** {user.get('email', 'User')}
136
+ """)
137
+
138
+ # ============================================
139
+ # LOGIN PAGE
140
+ # ============================================
141
 
142
  def show_login_page():
143
+ """Show login page if user is not authenticated"""
144
  GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "")
145
 
146
  if not GOOGLE_CLIENT_ID:
147
+ st.error("""
148
+ ⚠️ **Google OAuth not configured!**
149
+
150
+ Please add these secrets to HuggingFace Space Settings:
151
+
152
+ 1. Go to: Settings β†’ Repository Secrets
153
+ 2. Add: `GOOGLE_CLIENT_ID` (your Google Client ID)
154
+ 3. Add: `GOOGLE_CLIENT_SECRET` (your Google Client Secret)
155
+ 4. Restart the Space
156
+ """)
157
  return
158
 
159
+ # Apply styling for login page
160
+ st.markdown("""
161
+ <style>
162
+ .login-container {
163
+ max-width: 500px;
164
+ margin: 0 auto;
165
+ padding: 2rem;
166
+ text-align: center;
167
+ }
168
+ .google-btn {
169
+ background: linear-gradient(135deg, #4285F4, #34A853);
170
  color: white;
171
  padding: 15px 30px;
172
  border-radius: 8px;
 
174
  cursor: pointer;
175
  font-size: 18px;
176
  font-weight: 600;
177
+ display: inline-flex;
178
+ align-items: center;
179
+ justify-content: center;
180
+ gap: 12px;
181
+ margin: 20px 0;
182
+ text-decoration: none;
183
+ transition: all 0.3s ease;
184
+ }
185
+ .google-btn:hover {
186
+ transform: translateY(-2px);
187
+ box-shadow: 0 6px 20px rgba(66, 133, 244, 0.4);
188
+ }
189
+ </style>
190
+ """, unsafe_allow_html=True)
191
+
192
+ # Login page content
193
+ st.markdown("""
194
+ <div class="login-container">
195
+ <h1>πŸ” Social Media Data Extractor</h1>
196
+ <p style="font-size: 1.2rem; opacity: 0.9;">Secure login required to access extraction tools</p>
197
+ <hr style="margin: 2rem 0;">
198
+ </div>
199
+ """, unsafe_allow_html=True)
200
+
201
+ st.markdown("### Welcome! Please login to continue")
202
+
203
+ # Create login URL
204
+ redirect_uri = "https://refat81-social-media-data-extractor-chatbot.hf.space/oauth_callback"
205
+ 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"
206
+
207
+ # Google login button
208
+ st.markdown(f"""
209
+ <div style="text-align: center;">
210
+ <a href="{login_url}" class="google-btn">
211
+ <img src="https://cdn-icons-png.flaticon.com/512/2991/2991148.png" width="24" height="24">
212
  Sign in with Google
213
+ </a>
214
+ </div>
215
  """, unsafe_allow_html=True)
216
+
217
+ # Instructions
218
+ st.markdown("---")
219
+ with st.expander("ℹ️ About this login", expanded=False):
220
+ st.markdown("""
221
+ **Why login is required:**
222
+ - Securely store your extracted data
223
+ - Prevent unauthorized access
224
+ - Personalize your experience
225
+ - Track your usage history
226
+
227
+ **Privacy:** We only access your email and profile picture.
228
+ Your data is never shared with third parties.
229
+ """)
230
+
231
+ # ============================================
232
+ # MAIN APP
233
+ # ============================================
234
+
235
+ def main():
236
+ """Main app routing"""
237
+ st.set_page_config(
238
+ page_title="Social Media Data Extractor",
239
+ page_icon="πŸ”",
240
+ layout="wide",
241
+ initial_sidebar_state="expanded"
242
+ )
243
+
244
+ # Check if user is logged in
245
+ if "authenticated" in st.session_state and st.session_state.authenticated:
246
+ show_dashboard()
247
+ else:
248
+ show_login_page()
249
 
250
  if __name__ == "__main__":
251
  main()