Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,6 @@
|
|
| 1 |
-
# app.py -
|
| 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 |
-
#
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
st.sidebar.write(f"Session key: {'β
' if session_key else 'β'}")
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 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={
|
| 80 |
|
| 81 |
-
# Google login button
|
| 82 |
st.markdown(f"""
|
| 83 |
<a href="{login_url}">
|
| 84 |
<div style="
|
| 85 |
-
background:
|
| 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 |
-
|
| 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()
|