Nipun Claude commited on
Commit
3645162
·
1 Parent(s): 813c618

Fix UI slowness with caching and improve harder questions with specific locations/time

Browse files

PERFORMANCE 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]>

Files changed (2) hide show
  1. app.py +21 -12
  2. questions.txt +4 -4
app.py CHANGED
@@ -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 error handling
 
 
 
 
563
  try:
564
- df = preprocess_and_load_df(join(self_path, "Data.csv"))
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
- questions = []
580
- questions_file = join(self_path, "questions.txt")
581
- if os.path.exists(questions_file):
582
- try:
583
- with open(questions_file, 'r', encoding='utf-8') as f:
584
- content = f.read()
585
- questions = [q.strip() for q in content.split("\n") if q.strip()]
586
- except Exception as e:
587
- questions = []
 
 
 
 
 
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:
questions.txt CHANGED
@@ -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 records highest variability in PM2.5?
12
- Calculate pollution improvement rate year-over-year by city
13
- Identify cities with PM2.5 levels consistently above 50 μg/m³ for >6 months
14
- Find correlation between PM2.5 and PM10 across different seasons and cities
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