File size: 1,304 Bytes
fa85a62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Reddit Scraper Hugging Face Space Launcher
# This file serves as the entry point for our Hugging Face Space

import os
import streamlit as st
from dotenv import load_dotenv

# Load environment variables from .streamlit/secrets.toml if in Hugging Face Space Environment
def load_huggingface_secrets():
    try:
        # HF Spaces store secrets in st.secrets
        client_id = st.secrets.get("REDDIT_CLIENT_ID", "")
        client_secret = st.secrets.get("REDDIT_CLIENT_SECRET", "")
        user_agent = st.secrets.get("REDDIT_USER_AGENT", "RedditScraperApp/1.0")
        
        # Set as environment variables for other modules to use
        if client_id:
            os.environ["REDDIT_CLIENT_ID"] = client_id
        if client_secret:
            os.environ["REDDIT_CLIENT_SECRET"] = client_secret
        if user_agent:
            os.environ["REDDIT_USER_AGENT"] = user_agent
            
        return True
    except Exception:
        # Fallback to regular .env file if not in HF Space
        return False

# Try to load secrets (first from HF secrets, then from .env)
load_huggingface_secrets()
load_dotenv()

# Import the main app after environment setup to ensure it has access to variables
from advanced_scraper_ui import main

# Run the main app
if __name__ == "__main__":
    main()