Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,33 @@
|
|
| 1 |
-
# app.py -
|
| 2 |
import streamlit as st
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
|
| 6 |
-
# Debug
|
| 7 |
-
print("===
|
| 8 |
-
print(f"
|
| 9 |
-
print(f"Files: {os.listdir('.')}", file=sys.stderr)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# Simple app that works even without secrets
|
| 16 |
def main():
|
| 17 |
st.set_page_config(
|
| 18 |
page_title="Social Media Data Extractor",
|
|
@@ -20,97 +35,96 @@ def main():
|
|
| 20 |
layout="wide"
|
| 21 |
)
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
except:
|
| 30 |
-
print("Secrets NOT loaded", file=sys.stderr)
|
| 31 |
-
secrets_loaded = False
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
st.
|
| 35 |
-
st.
|
|
|
|
| 36 |
|
| 37 |
-
if
|
|
|
|
| 38 |
st.error("""
|
| 39 |
-
β οΈ **
|
| 40 |
-
|
| 41 |
-
**Please check:**
|
| 42 |
-
|
| 43 |
-
1. **HuggingFace Secrets** are configured in Space Settings
|
| 44 |
-
2. Secret name is exactly: `STREAMLIT_SECRETS_TOML`
|
| 45 |
-
3. The secret contains valid TOML format
|
| 46 |
-
|
| 47 |
-
**To fix this:**
|
| 48 |
-
|
| 49 |
-
1. Go to your Space: https://huggingface.co/spaces/Refat81/Social_Media_Data_Extractor_Chatbot/settings
|
| 50 |
-
2. Click "Repository secrets"
|
| 51 |
-
3. Add a secret named: `STREAMLIT_SECRETS_TOML`
|
| 52 |
-
4. Paste this (with your actual values):
|
| 53 |
|
| 54 |
-
|
| 55 |
-
[google]
|
| 56 |
-
client_id = "your-client-id.apps.googleusercontent.com"
|
| 57 |
-
client_secret = "your-client-secret"
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
""")
|
| 69 |
return
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
if client_id == "placeholder-client-id":
|
| 75 |
-
st.warning("β οΈ Using placeholder credentials. Please add real Google OAuth credentials.")
|
| 76 |
-
return
|
| 77 |
-
except:
|
| 78 |
-
st.error("Google OAuth not configured in secrets")
|
| 79 |
-
return
|
| 80 |
-
|
| 81 |
-
# Show login button
|
| 82 |
st.markdown("### Welcome! Please login to continue")
|
| 83 |
|
| 84 |
# Create login URL
|
| 85 |
redirect_uri = "https://refat81-social-media-data-extractor-chatbot.hf.space/oauth_callback"
|
| 86 |
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"
|
| 87 |
|
|
|
|
| 88 |
st.markdown(f"""
|
| 89 |
-
<a href="{login_url}"
|
| 90 |
<div style="
|
| 91 |
-
background
|
| 92 |
color: white;
|
| 93 |
padding: 15px 30px;
|
| 94 |
border-radius: 8px;
|
| 95 |
border: none;
|
| 96 |
cursor: pointer;
|
| 97 |
-
font-size:
|
| 98 |
-
font-weight:
|
| 99 |
text-align: center;
|
| 100 |
-
margin:
|
| 101 |
display: inline-block;
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
Sign in with Google
|
| 105 |
</div>
|
| 106 |
</a>
|
| 107 |
""", unsafe_allow_html=True)
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
st.markdown("---")
|
| 110 |
-
st.
|
| 111 |
-
**Note:** First-time login might show "App not verified" warning.
|
| 112 |
-
Click "Continue" to proceed (this is normal for testing).
|
| 113 |
-
""")
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|
| 116 |
main()
|
|
|
|
| 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(
|
| 33 |
page_title="Social Media Data Extractor",
|
|
|
|
| 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;
|
| 89 |
border: none;
|
| 90 |
cursor: pointer;
|
| 91 |
+
font-size: 18px;
|
| 92 |
+
font-weight: 600;
|
| 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()
|