Spaces:
Running
Running
Fix Streamlit page config to resolve Hugging Face deployment error
Browse files- advanced_scraper_ui.py +1 -35
- app.py +69 -3
advanced_scraper_ui.py
CHANGED
@@ -9,41 +9,7 @@ from datetime import datetime
|
|
9 |
from dotenv import load_dotenv
|
10 |
from enhanced_scraper import EnhancedRedditScraper
|
11 |
|
12 |
-
# Page configuration
|
13 |
-
st.set_page_config(
|
14 |
-
page_title="Advanced Reddit Scraper",
|
15 |
-
page_icon="π",
|
16 |
-
layout="wide",
|
17 |
-
initial_sidebar_state="expanded"
|
18 |
-
)
|
19 |
-
|
20 |
-
# Add custom CSS
|
21 |
-
st.markdown("""
|
22 |
-
<style>
|
23 |
-
.main-header {
|
24 |
-
font-size: 2.5rem;
|
25 |
-
margin-bottom: 1rem;
|
26 |
-
}
|
27 |
-
.subheader {
|
28 |
-
font-size: 1.5rem;
|
29 |
-
color: #ff4500;
|
30 |
-
margin-bottom: 1rem;
|
31 |
-
}
|
32 |
-
.card {
|
33 |
-
padding: 1rem;
|
34 |
-
border-radius: 0.5rem;
|
35 |
-
margin-bottom: 1rem;
|
36 |
-
border: 1px solid #ddd;
|
37 |
-
}
|
38 |
-
.small-text {
|
39 |
-
font-size: 0.8rem;
|
40 |
-
color: #777;
|
41 |
-
}
|
42 |
-
.stButton button {
|
43 |
-
width: 100%;
|
44 |
-
}
|
45 |
-
</style>
|
46 |
-
""", unsafe_allow_html=True)
|
47 |
|
48 |
# Session state initialization
|
49 |
if 'results' not in st.session_state:
|
|
|
9 |
from dotenv import load_dotenv
|
10 |
from enhanced_scraper import EnhancedRedditScraper
|
11 |
|
12 |
+
# Note: Page configuration moved to app.py for Hugging Face Space compatibility
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Session state initialization
|
15 |
if 'results' not in st.session_state:
|
app.py
CHANGED
@@ -5,6 +5,14 @@ import os
|
|
5 |
import streamlit as st
|
6 |
from dotenv import load_dotenv
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# Load environment variables from .streamlit/secrets.toml if in Hugging Face Space Environment
|
9 |
def load_huggingface_secrets():
|
10 |
try:
|
@@ -30,9 +38,67 @@ def load_huggingface_secrets():
|
|
30 |
load_huggingface_secrets()
|
31 |
load_dotenv()
|
32 |
|
33 |
-
#
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Run the main app
|
37 |
if __name__ == "__main__":
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import streamlit as st
|
6 |
from dotenv import load_dotenv
|
7 |
|
8 |
+
# Configure Streamlit page
|
9 |
+
st.set_page_config(
|
10 |
+
page_title="Reddit Scraper",
|
11 |
+
page_icon="π",
|
12 |
+
layout="wide",
|
13 |
+
initial_sidebar_state="expanded"
|
14 |
+
)
|
15 |
+
|
16 |
# Load environment variables from .streamlit/secrets.toml if in Hugging Face Space Environment
|
17 |
def load_huggingface_secrets():
|
18 |
try:
|
|
|
38 |
load_huggingface_secrets()
|
39 |
load_dotenv()
|
40 |
|
41 |
+
# Add custom CSS
|
42 |
+
st.markdown("""
|
43 |
+
<style>
|
44 |
+
.main-header {
|
45 |
+
font-size: 2.5rem;
|
46 |
+
margin-bottom: 1rem;
|
47 |
+
}
|
48 |
+
.subheader {
|
49 |
+
font-size: 1.5rem;
|
50 |
+
color: #ff4500;
|
51 |
+
margin-bottom: 1rem;
|
52 |
+
}
|
53 |
+
.card {
|
54 |
+
padding: 1rem;
|
55 |
+
border-radius: 0.5rem;
|
56 |
+
margin-bottom: 1rem;
|
57 |
+
border: 1px solid #ddd;
|
58 |
+
}
|
59 |
+
.small-text {
|
60 |
+
font-size: 0.8rem;
|
61 |
+
color: #777;
|
62 |
+
}
|
63 |
+
.stButton button {
|
64 |
+
width: 100%;
|
65 |
+
}
|
66 |
+
</style>
|
67 |
+
""", unsafe_allow_html=True)
|
68 |
+
|
69 |
+
# Now import functions from the UI module
|
70 |
+
# But not the whole file to avoid st.set_page_config being called twice
|
71 |
+
import sys
|
72 |
+
import importlib.util
|
73 |
+
|
74 |
+
# Import individual functions from advanced_scraper_ui
|
75 |
+
spec = importlib.util.spec_from_file_location("advanced_scraper_ui", "advanced_scraper_ui.py")
|
76 |
+
ui_module = importlib.util.module_from_spec(spec)
|
77 |
+
sys.modules["advanced_scraper_ui"] = ui_module
|
78 |
+
spec.loader.exec_module(ui_module)
|
79 |
|
80 |
# Run the main app
|
81 |
if __name__ == "__main__":
|
82 |
+
try:
|
83 |
+
# Call the main function without re-importing the whole module
|
84 |
+
ui_module.main()
|
85 |
+
except Exception as e:
|
86 |
+
st.error(f"Error running the application: {str(e)}")
|
87 |
+
st.error("This might be due to missing Reddit API credentials.")
|
88 |
+
|
89 |
+
# Display instructions for setting up credentials
|
90 |
+
st.markdown("""
|
91 |
+
## Setting up Reddit API Credentials
|
92 |
+
|
93 |
+
This app requires Reddit API credentials to function properly. You can:
|
94 |
+
|
95 |
+
1. Enter your credentials directly in the sidebar when the app loads, or
|
96 |
+
2. Set them up as Hugging Face Space secrets (if you've duplicated this Space)
|
97 |
+
|
98 |
+
To obtain Reddit API credentials:
|
99 |
+
1. Go to https://www.reddit.com/prefs/apps
|
100 |
+
2. Click "Create App" or "Create Another App"
|
101 |
+
3. Fill in the details and select "script" as the application type
|
102 |
+
4. Use "http://localhost:8000" as the redirect URI
|
103 |
+
5. Take note of the client ID and client secret
|
104 |
+
""")
|