milwright commited on
Commit
e5ce70d
·
1 Parent(s): c347de0

Update UI files with visualization fixes from main branch

Browse files
Files changed (2) hide show
  1. advanced_scraper_ui.py +20 -24
  2. app.py +15 -23
advanced_scraper_ui.py CHANGED
@@ -556,9 +556,26 @@ def main():
556
 
557
  # Tab 5: API Credentials - Auto-closed by default
558
  with tab5:
559
- # Display welcome message if credentials are not set
560
- if not os.environ.get("REDDIT_CLIENT_ID") and not os.environ.get("REDDIT_CLIENT_SECRET"):
561
- st.info("👋 Welcome to Reddit Scraper!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
 
563
  # Two columns for instructions and input
564
  cred_col1, cred_col2 = st.columns([1, 1])
@@ -580,27 +597,6 @@ def main():
580
  """)
581
 
582
  with cred_col2:
583
- # Initialize session state for credentials if they don't exist
584
- if 'client_id' not in st.session_state:
585
- st.session_state.client_id = ""
586
- if 'client_secret' not in st.session_state:
587
- st.session_state.client_secret = ""
588
- if 'user_agent' not in st.session_state:
589
- st.session_state.user_agent = "RedditScraperApp/1.0"
590
-
591
- # In development environment, try to load from .env file for convenience
592
- # But don't do this in production to avoid credential leakage
593
- is_local_dev = not os.environ.get('SPACE_ID') and not os.environ.get('SYSTEM')
594
- if is_local_dev:
595
- load_dotenv()
596
- # Only load from env if session state is empty (first load)
597
- if not st.session_state.client_id:
598
- st.session_state.client_id = os.environ.get("REDDIT_CLIENT_ID", "")
599
- if not st.session_state.client_secret:
600
- st.session_state.client_secret = os.environ.get("REDDIT_CLIENT_SECRET", "")
601
- if st.session_state.user_agent == "RedditScraperApp/1.0":
602
- st.session_state.user_agent = os.environ.get("REDDIT_USER_AGENT", "RedditScraperApp/1.0")
603
-
604
  # Use session state for the input values
605
  client_id = st.text_input("Client ID", value=st.session_state.client_id, key="client_id_input")
606
  client_secret = st.text_input("Client Secret", value=st.session_state.client_secret, type="password", key="client_secret_input")
 
556
 
557
  # Tab 5: API Credentials - Auto-closed by default
558
  with tab5:
559
+ # Initialize session state for credentials if they don't exist
560
+ if 'client_id' not in st.session_state:
561
+ st.session_state.client_id = ""
562
+ if 'client_secret' not in st.session_state:
563
+ st.session_state.client_secret = ""
564
+ if 'user_agent' not in st.session_state:
565
+ st.session_state.user_agent = "RedditScraperApp/1.0"
566
+
567
+ # In development environment, try to load from .env file for convenience
568
+ # But don't do this in production to avoid credential leakage
569
+ is_local_dev = not os.environ.get('SPACE_ID') and not os.environ.get('SYSTEM')
570
+ if is_local_dev:
571
+ load_dotenv()
572
+ # Only load from env if session state is empty (first load)
573
+ if not st.session_state.client_id:
574
+ st.session_state.client_id = os.environ.get("REDDIT_CLIENT_ID", "")
575
+ if not st.session_state.client_secret:
576
+ st.session_state.client_secret = os.environ.get("REDDIT_CLIENT_SECRET", "")
577
+ if st.session_state.user_agent == "RedditScraperApp/1.0":
578
+ st.session_state.user_agent = os.environ.get("REDDIT_USER_AGENT", "RedditScraperApp/1.0")
579
 
580
  # Two columns for instructions and input
581
  cred_col1, cred_col2 = st.columns([1, 1])
 
597
  """)
598
 
599
  with cred_col2:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600
  # Use session state for the input values
601
  client_id = st.text_input("Client ID", value=st.session_state.client_id, key="client_id_input")
602
  client_secret = st.text_input("Client Secret", value=st.session_state.client_secret, type="password", key="client_secret_input")
app.py CHANGED
@@ -1,7 +1,3 @@
1
- # Add warning suppression at the very beginning before any other imports
2
- import warnings
3
- warnings.filterwarnings("ignore", message="No secrets files found.*")
4
-
5
  import streamlit as st
6
  import os
7
  from dotenv import load_dotenv
@@ -48,25 +44,21 @@ st.markdown("""
48
  """, unsafe_allow_html=True)
49
 
50
  # Load Hugging Face secrets if available
51
- # Use a more silent approach to hide the "No secrets files found" message
52
- import warnings
53
- with warnings.catch_warnings():
54
- warnings.simplefilter("ignore")
55
- try:
56
- client_id = st.secrets.get("REDDIT_CLIENT_ID", "")
57
- client_secret = st.secrets.get("REDDIT_CLIENT_SECRET", "")
58
- user_agent = st.secrets.get("REDDIT_USER_AGENT", "RedditScraperApp/1.0")
59
-
60
- # Set as environment variables for other modules to use
61
- if client_id:
62
- os.environ["REDDIT_CLIENT_ID"] = client_id
63
- if client_secret:
64
- os.environ["REDDIT_CLIENT_SECRET"] = client_secret
65
- if user_agent:
66
- os.environ["REDDIT_USER_AGENT"] = user_agent
67
- except Exception as e:
68
- # No secrets configured, will fall back to user input
69
- pass
70
 
71
  # Now that setup is complete, import the main function
72
  from enhanced_scraper import EnhancedRedditScraper
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
  from dotenv import load_dotenv
 
44
  """, unsafe_allow_html=True)
45
 
46
  # Load Hugging Face secrets if available
47
+ try:
48
+ client_id = st.secrets.get("REDDIT_CLIENT_ID", "")
49
+ client_secret = st.secrets.get("REDDIT_CLIENT_SECRET", "")
50
+ user_agent = st.secrets.get("REDDIT_USER_AGENT", "RedditScraperApp/1.0")
51
+
52
+ # Set as environment variables for other modules to use
53
+ if client_id:
54
+ os.environ["REDDIT_CLIENT_ID"] = client_id
55
+ if client_secret:
56
+ os.environ["REDDIT_CLIENT_SECRET"] = client_secret
57
+ if user_agent:
58
+ os.environ["REDDIT_USER_AGENT"] = user_agent
59
+ except Exception as e:
60
+ # No secrets configured, will fall back to user input
61
+ pass
 
 
 
 
62
 
63
  # Now that setup is complete, import the main function
64
  from enhanced_scraper import EnhancedRedditScraper