Fix UI slowness with caching and improve harder questions with specific locations/time
Browse filesPERFORMANCE IMPROVEMENTS:
- Add
@st
.cache_data to data loading function to prevent reloading Data.csv on every interaction
- Add
@st
.cache_data to questions loading to cache questions.txt file reads
- These should significantly speed up initial UI loading
IMPROVED HARDER QUESTIONS:
- 'Which station in Ahmedabad shows highest PM2.5 variability in winter 2023?'
- 'Calculate PM2.5 improvement rate from 2022 to 2023 for Mumbai vs Delhi'
- 'Identify Gujarat cities with PM2.5 >50 μg/m³ for 6+ consecutive months in 2023'
- 'Compare PM2.5 vs PM10 correlation: winter vs summer across top 5 polluted cities'
Now questions are more specific with actual locations (Ahmedabad, Mumbai, Delhi, Gujarat) and time periods (winter 2023, 2022-2023, etc.)
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
- app.py +21 -12
- questions.txt +4 -4
@@ -559,9 +559,13 @@ with header_col2:
|
|
559 |
st.markdown("<hr style='margin: 0.25rem 0; border: none; border-top: 1px solid #e2e8f0;'>", unsafe_allow_html=True)
|
560 |
|
561 |
|
562 |
-
# Load data with
|
|
|
|
|
|
|
|
|
563 |
try:
|
564 |
-
df =
|
565 |
# Data loaded silently - no success message needed
|
566 |
except Exception as e:
|
567 |
st.error(f"Error loading data: {e}")
|
@@ -575,16 +579,21 @@ with st.sidebar:
|
|
575 |
# Quick Queries Section - moved to top
|
576 |
st.markdown("### Quick Queries")
|
577 |
|
578 |
-
# Load quick prompts
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
|
|
|
|
|
|
|
|
|
|
588 |
|
589 |
# Add default prompts if file doesn't exist or is empty
|
590 |
if not questions:
|
|
|
559 |
st.markdown("<hr style='margin: 0.25rem 0; border: none; border-top: 1px solid #e2e8f0;'>", unsafe_allow_html=True)
|
560 |
|
561 |
|
562 |
+
# Load data with caching for better performance
|
563 |
+
@st.cache_data
|
564 |
+
def load_data():
|
565 |
+
return preprocess_and_load_df(join(self_path, "Data.csv"))
|
566 |
+
|
567 |
try:
|
568 |
+
df = load_data()
|
569 |
# Data loaded silently - no success message needed
|
570 |
except Exception as e:
|
571 |
st.error(f"Error loading data: {e}")
|
|
|
579 |
# Quick Queries Section - moved to top
|
580 |
st.markdown("### Quick Queries")
|
581 |
|
582 |
+
# Load quick prompts with caching
|
583 |
+
@st.cache_data
|
584 |
+
def load_questions():
|
585 |
+
questions = []
|
586 |
+
questions_file = join(self_path, "questions.txt")
|
587 |
+
if os.path.exists(questions_file):
|
588 |
+
try:
|
589 |
+
with open(questions_file, 'r', encoding='utf-8') as f:
|
590 |
+
content = f.read()
|
591 |
+
questions = [q.strip() for q in content.split("\n") if q.strip()]
|
592 |
+
except Exception as e:
|
593 |
+
questions = []
|
594 |
+
return questions
|
595 |
+
|
596 |
+
questions = load_questions()
|
597 |
|
598 |
# Add default prompts if file doesn't exist or is empty
|
599 |
if not questions:
|
@@ -8,10 +8,10 @@ Show seasonal pollution patterns
|
|
8 |
Which areas exceed WHO guidelines?
|
9 |
What are peak pollution hours?
|
10 |
Show PM10 vs PM2.5 comparison
|
11 |
-
Which station
|
12 |
-
Calculate
|
13 |
-
Identify cities with PM2.5
|
14 |
-
|
15 |
Compare weekday vs weekend levels
|
16 |
Plot yearly trend analysis
|
17 |
Show pollution distribution by city
|
|
|
8 |
Which areas exceed WHO guidelines?
|
9 |
What are peak pollution hours?
|
10 |
Show PM10 vs PM2.5 comparison
|
11 |
+
Which station in Ahmedabad shows highest PM2.5 variability in winter 2023?
|
12 |
+
Calculate PM2.5 improvement rate from 2022 to 2023 for Mumbai vs Delhi
|
13 |
+
Identify Gujarat cities with PM2.5 >50 μg/m³ for 6+ consecutive months in 2023
|
14 |
+
Compare PM2.5 vs PM10 correlation: winter vs summer across top 5 polluted cities
|
15 |
Compare weekday vs weekend levels
|
16 |
Plot yearly trend analysis
|
17 |
Show pollution distribution by city
|