Nipun Claude commited on
Commit
e939a33
·
1 Parent(s): b3e34c9

Enhance VayuChat with retry functionality and improved UX

Browse files

- Set DeepSeek-R1 as default model with GPT-OSS fallback
- Add retry button for regenerating responses with current model
- Expand question visibility from 20 to all 30 questions organized in categories:
* NCAP Funding & Policy Analysis
* Meteorology & Environmental Factors
* Population & Demographics
* Multi-Pollutant Analysis
* Other Analysis Questions
- Improve chat UI: increase message width from 70% to 85%, fix input width
- Update questions.txt with concrete policy-relevant queries
- Add seaborn to available libraries in system prompt

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

Files changed (3) hide show
  1. app.py +73 -10
  2. questions.txt +30 -31
  3. system_prompt.txt +1 -0
app.py CHANGED
@@ -158,7 +158,7 @@ st.markdown("""
158
  color: white;
159
  padding: 0.75rem 1rem;
160
  border-radius: 12px;
161
- max-width: 70%;
162
  }
163
 
164
  .user-info {
@@ -173,7 +173,7 @@ st.markdown("""
173
  color: #334155;
174
  padding: 0.75rem 1rem;
175
  border-radius: 12px;
176
- max-width: 70%;
177
  }
178
 
179
  .assistant-info {
@@ -235,6 +235,8 @@ st.markdown("""
235
  background: #ffffff;
236
  padding: 0.75rem 1rem;
237
  font-size: 1rem;
 
 
238
  }
239
 
240
  .stChatInput:focus {
@@ -563,9 +565,11 @@ if not available_models:
563
  st.error("No API keys available! Please set up your API keys in the .env file")
564
  st.stop()
565
 
566
- # Set GPT-OSS-120B as default if available
567
  default_index = 0
568
- if "gpt-oss-120b" in available_models:
 
 
569
  default_index = available_models.index("gpt-oss-120b")
570
 
571
  # Simple header - just title and model selector
@@ -644,12 +648,45 @@ with st.sidebar:
644
  selected_prompt = None
645
 
646
 
647
- for i, question in enumerate(questions[:20]): # Show more questions including policy-focused ones
648
- # Simple left-aligned buttons without icons for cleaner look
649
- if st.button(question, key=f"sidebar_prompt_{i}", use_container_width=True, help=f"Click to analyze: {question}"):
650
- if question != st.session_state.get("last_selected_prompt"):
651
- selected_prompt = question
652
- st.session_state.last_selected_prompt = question
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
653
 
654
  st.markdown("---")
655
 
@@ -815,6 +852,32 @@ for response_id, response in enumerate(st.session_state.responses):
815
  st.session_state.responses[response_id]["feedback"] = feedback
816
  st.success("Thanks for your feedback!")
817
  st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
818
 
819
  # Chat input with better guidance
820
  prompt = st.chat_input("💬 Ask about air quality trends, compare cities, or request visualizations...", key="main_chat")
 
158
  color: white;
159
  padding: 0.75rem 1rem;
160
  border-radius: 12px;
161
+ max-width: 85%;
162
  }
163
 
164
  .user-info {
 
173
  color: #334155;
174
  padding: 0.75rem 1rem;
175
  border-radius: 12px;
176
+ max-width: 85%;
177
  }
178
 
179
  .assistant-info {
 
235
  background: #ffffff;
236
  padding: 0.75rem 1rem;
237
  font-size: 1rem;
238
+ width: 100% !important;
239
+ max-width: none !important;
240
  }
241
 
242
  .stChatInput:focus {
 
565
  st.error("No API keys available! Please set up your API keys in the .env file")
566
  st.stop()
567
 
568
+ # Set DeepSeek-R1 as default if available
569
  default_index = 0
570
+ if "deepseek-R1" in available_models:
571
+ default_index = available_models.index("deepseek-R1")
572
+ elif "gpt-oss-120b" in available_models:
573
  default_index = available_models.index("gpt-oss-120b")
574
 
575
  # Simple header - just title and model selector
 
648
  selected_prompt = None
649
 
650
 
651
+ # Show all questions but in a scrollable format
652
+ if len(questions) > 0:
653
+ st.markdown("**Select a question to analyze:**")
654
+ # Create expandable sections for better organization
655
+ with st.expander("📊 NCAP Funding & Policy Analysis", expanded=True):
656
+ for i, q in enumerate([q for q in questions if any(word in q.lower() for word in ['ncap', 'funding', 'investment', 'rupee'])]):
657
+ if st.button(q, key=f"ncap_q_{i}", use_container_width=True, help=f"Analyze: {q}"):
658
+ selected_prompt = q
659
+ st.session_state.last_selected_prompt = q
660
+
661
+ with st.expander("🌬️ Meteorology & Environmental Factors", expanded=False):
662
+ for i, q in enumerate([q for q in questions if any(word in q.lower() for word in ['wind', 'temperature', 'humidity', 'rainfall', 'meteorological', 'monsoon', 'barometric'])]):
663
+ if st.button(q, key=f"met_q_{i}", use_container_width=True, help=f"Analyze: {q}"):
664
+ selected_prompt = q
665
+ st.session_state.last_selected_prompt = q
666
+
667
+ with st.expander("👥 Population & Demographics", expanded=False):
668
+ for i, q in enumerate([q for q in questions if any(word in q.lower() for word in ['population', 'capita', 'density', 'exposure'])]):
669
+ if st.button(q, key=f"pop_q_{i}", use_container_width=True, help=f"Analyze: {q}"):
670
+ selected_prompt = q
671
+ st.session_state.last_selected_prompt = q
672
+
673
+ with st.expander("🏭 Multi-Pollutant Analysis", expanded=False):
674
+ for i, q in enumerate([q for q in questions if any(word in q.lower() for word in ['ozone', 'no2', 'correlation', 'multi-pollutant', 'interaction'])]):
675
+ if st.button(q, key=f"multi_q_{i}", use_container_width=True, help=f"Analyze: {q}"):
676
+ selected_prompt = q
677
+ st.session_state.last_selected_prompt = q
678
+
679
+ with st.expander("📈 Other Analysis Questions", expanded=False):
680
+ remaining_questions = [q for q in questions if not any(any(word in q.lower() for word in category) for category in [
681
+ ['ncap', 'funding', 'investment', 'rupee'],
682
+ ['wind', 'temperature', 'humidity', 'rainfall', 'meteorological', 'monsoon', 'barometric'],
683
+ ['population', 'capita', 'density', 'exposure'],
684
+ ['ozone', 'no2', 'correlation', 'multi-pollutant', 'interaction']
685
+ ])]
686
+ for i, q in enumerate(remaining_questions):
687
+ if st.button(q, key=f"other_q_{i}", use_container_width=True, help=f"Analyze: {q}"):
688
+ selected_prompt = q
689
+ st.session_state.last_selected_prompt = q
690
 
691
  st.markdown("---")
692
 
 
852
  st.session_state.responses[response_id]["feedback"] = feedback
853
  st.success("Thanks for your feedback!")
854
  st.rerun()
855
+
856
+ # Add retry button for each assistant response
857
+ col1, col2, col3 = st.columns([1, 1, 2])
858
+ with col1:
859
+ if st.button("🔄 Retry", key=f"retry_{response_id}", help="Regenerate this response with current model"):
860
+ # Get the last user prompt that led to this response
861
+ user_prompt = ""
862
+ if response_id > 0:
863
+ user_prompt = st.session_state.responses[response_id-1].get("content", "")
864
+
865
+ if user_prompt:
866
+ # Remove this response and the user message before it, then re-add the user message
867
+ if response_id > 0:
868
+ # Store the user prompt
869
+ retry_prompt = st.session_state.responses[response_id-1].get("content", "")
870
+ # Remove both user message and assistant response
871
+ del st.session_state.responses[response_id]
872
+ del st.session_state.responses[response_id-1]
873
+ # Re-add user message and trigger new response
874
+ st.session_state.follow_up_prompt = retry_prompt
875
+ st.rerun()
876
+
877
+ with col2:
878
+ if st.button("💬 Follow-up", key=f"followup_{response_id}", help="Ask a follow-up question"):
879
+ st.session_state.follow_up_mode = True
880
+ st.rerun()
881
 
882
  # Chat input with better guidance
883
  prompt = st.chat_input("💬 Ask about air quality trends, compare cities, or request visualizations...", key="main_chat")
questions.txt CHANGED
@@ -1,31 +1,30 @@
1
- What percentage of India’s population lives in states where the average PM2.5 concentration exceeds 60 µg/m³?
2
- What is the correlation between wind speed and PM2.5 levels in Ahmedabad during July 2023?
3
- Which NCAP-funded city showed the greatest improvement in PM2.5 levels from 2018 to 2019?
4
- Which month in 2023 had the highest average PM2.5 pollution levels?
5
- Which city has the worst air quality based on average PM2.5 levels?
6
- Calculate the overall annual average PM2.5 concentration across all cities in 2023
7
- Plot monthly average PM2.5 trends for 2023 across all cities
8
- Rank all cities by average PM2.5 levels from highest to lowest pollution
9
- Compare average PM2.5 levels: winter months (Dec-Feb) vs summer months (Apr-Jun)
10
- Show seasonal PM2.5 patterns: which season has highest pollution levels?
11
- Which cities have annual average PM2.5 exceeding WHO guideline of 15 μg/m³?
12
- Identify the top 10 most polluted cities based on PM2.5 in 2023
13
- Compare PM10 vs PM2.5 correlation strength across different cities
14
- Which station in Ahmedabad shows highest PM2.5 variability in winter 2023?
15
- Calculate PM2.5 improvement rate from 2022 to 2023 for Mumbai vs Delhi
16
- Identify Gujarat cities with PM2.5 >50 μg/m³ for 6+ consecutive months in 2023
17
- Compare PM2.5 vs PM10 correlation: winter vs summer across top 5 polluted cities
18
- Compare average pollution levels: weekdays (Mon-Fri) vs weekends (Sat-Sun)
19
- Plot year-over-year PM2.5 trend from 2022 to 2023 for major cities
20
- Show PM2.5 distribution histogram across all cities and time periods
21
- Create scatter plot showing PM2.5 vs PM10 correlation with trend line
22
- Which cities need immediate emergency intervention with PM2.5 >100 μg/m³?
23
- Identify cities showing consistent pollution improvement for policy replication
24
- Which months require targeted interventions based on highest pollution spikes?
25
- Compare pollution levels between industrial vs non-industrial cities for policy focus
26
- Rank states by average air quality to prioritize national-level resource allocation
27
- Which cities have PM2.5 levels in 'hazardous' category (>250 μg/m³) requiring urgent action?
28
- Calculate population-weighted pollution exposure to identify areas affecting most people
29
- Show cities with worsening pollution trends that need immediate policy intervention
30
- Compare pollution reduction success: which cities improved most and how?
31
- Identify seasonal emergency periods when public health advisories should be issued
 
1
+ How much NCAP funding did Delhi receive vs its PM2.5 improvement from 2018-2023?
2
+ Which NCAP cities achieved the best PM2.5 reduction per rupee invested?
3
+ Does wind speed above 5 m/s significantly reduce PM2.5 levels in Delhi?
4
+ Show correlation between rainfall and PM2.5 reduction in Mumbai during monsoon
5
+ Which cities with high population have dangerously high PM2.5 exposure levels?
6
+ Compare winter PM2.5 levels: high-funded vs low-funded NCAP cities
7
+ Does temperature increase correlate with ozone levels in Chennai during summer?
8
+ Plot wind direction vs PM2.5 concentration rose diagram for Delhi in November
9
+ Which meteorological factor most influences PM2.5 reduction in Ahmedabad?
10
+ Rank NCAP cities by pollution improvement efficiency per capita funding
11
+ Show monthly PM2.5 trends for top 5 most populated Indian cities
12
+ Does humidity above 70% help reduce PM10 levels in coastal cities?
13
+ Compare NO2 vs PM2.5 correlation in traffic-heavy vs residential areas
14
+ Which NCAP-funded cities still exceed WHO PM2.5 guidelines despite investment?
15
+ Plot seasonal wind patterns vs pollution levels for North Indian cities
16
+ Show population-weighted pollution exposure map across Indian states
17
+ Does solar radiation intensity affect ground-level ozone formation patterns?
18
+ Compare NCAP investment effectiveness: Tier-1 vs Tier-2 cities
19
+ Which high-population cities need emergency NCAP funding based on current PM2.5?
20
+ Show correlation between barometric pressure and pollution accumulation
21
+ Does monsoon season consistently reduce all pollutant levels nationwide?
22
+ Compare multi-pollutant exposure: children vs adults in high-density cities
23
+ Which cities show pollution improvement correlated with NCAP timeline?
24
+ Plot wind speed threshold for effective pollution dispersion by region
25
+ Show relationship between city population density and average PM2.5 exposure
26
+ Compare Ozone-PM2.5-NO2 interaction patterns in Delhi vs Mumbai
27
+ Does vector wind speed predict pollution episodes better than average wind speed?
28
+ Which NCAP phases (1,2,3) showed maximum pollution reduction per investment?
29
+ Show real-time impact: do meteorological alerts help predict pollution spikes?
30
+ Create pollution risk index combining PM2.5, population, and meteorology data
 
system_prompt.txt CHANGED
@@ -3,6 +3,7 @@ I have a pandas dataframe data of PM2.5 and PM10.
3
  * Frequency of data is daily.
4
  * `pollution` generally means `PM2.5`.
5
  * You already have df, so don't read the csv file
 
6
  * Don't print anything, but save result in a variable `answer` and make it global.
7
  * Unless explicitly mentioned, don't consider the result as a plot.
8
  * PM2.5 guidelines: India: 60, WHO: 15.
 
3
  * Frequency of data is daily.
4
  * `pollution` generally means `PM2.5`.
5
  * You already have df, so don't read the csv file
6
+ * Available libraries: pandas, matplotlib, numpy, seaborn, plotly, geopandas, statsmodels, scikit-learn
7
  * Don't print anything, but save result in a variable `answer` and make it global.
8
  * Unless explicitly mentioned, don't consider the result as a plot.
9
  * PM2.5 guidelines: India: 60, WHO: 15.