few changes

This commit is contained in:
Madhu 2025-02-21 01:06:33 +05:30
parent eb17161e04
commit 2e8b254391

View file

@ -39,6 +39,7 @@ class AQIAnalyzer:
return f"https://www.aqi.in/dashboard/{country.lower().replace(' ', '-')}/{state.lower().replace(' ', '-')}/{city.lower().replace(' ', '-')}" return f"https://www.aqi.in/dashboard/{country.lower().replace(' ', '-')}/{state.lower().replace(' ', '-')}/{city.lower().replace(' ', '-')}"
def fetch_aqi_data(self, city: str, state: str, country: str) -> Dict[str, float]: def fetch_aqi_data(self, city: str, state: str, country: str) -> Dict[str, float]:
"""Fetch AQI data using Firecrawl"""
try: try:
url = self._format_url(country, state, city) url = self._format_url(country, state, city)
@ -50,10 +51,15 @@ class AQIAnalyzer:
} }
) )
# Parse Firecrawl response
aqi_response = AQIResponse(**response) aqi_response = AQIResponse(**response)
if not aqi_response.success: if not aqi_response.success:
raise ValueError(f"Failed to fetch AQI data: {aqi_response.status}") raise ValueError(f"Failed to fetch AQI data: {aqi_response.status}")
# Display raw data in expander
with st.expander("📊 Raw AQI Data", expanded=True):
st.json(aqi_response.data)
return aqi_response.data return aqi_response.data
except Exception as e: except Exception as e:
@ -107,10 +113,9 @@ class HealthRecommendationAgent:
Provide detailed health recommendations considering: Provide detailed health recommendations considering:
1. Current air quality impacts on health 1. Current air quality impacts on health
2. Safety precautions needed 2. Safety precautions needed for the planned activity of User based on the air quality conditions
3. Whether the planned activity is advisable 3. Whether the planned activity is advisable or not, if its not advisable then provide alternative activity suggestions
4. Alternative activity suggestions if needed 4. Best time to conduct the activity if applicable
5. Best time to conduct the activity if applicable
""" """
def analyze_conditions( def analyze_conditions(
@ -202,11 +207,14 @@ def render_main_content():
) )
def main(): def main():
"""Main application entry point"""
initialize_session_state() initialize_session_state()
setup_page() setup_page()
render_sidebar() render_sidebar()
user_input = render_main_content() user_input = render_main_content()
result = None # Initialize result variable
if st.button("🔍 Analyze & Get Recommendations"): if st.button("🔍 Analyze & Get Recommendations"):
if not all([user_input.city, user_input.state, user_input.planned_activity]): if not all([user_input.city, user_input.state, user_input.planned_activity]):
st.error("Please fill in all required fields (medical conditions are optional)") st.error("Please fill in all required fields (medical conditions are optional)")
@ -219,10 +227,15 @@ def main():
user_input=user_input, user_input=user_input,
api_keys=st.session_state.api_keys api_keys=st.session_state.api_keys
) )
st.success("✅ Analysis completed!") st.success("✅ Analysis completed!")
except Exception as e:
st.error(f"❌ Error: {str(e)}")
# Display recommendations if available
if result:
st.markdown("### 📊 Recommendations") st.markdown("### 📊 Recommendations")
st.info(result) st.markdown(result)
st.download_button( st.download_button(
"💾 Download Recommendations", "💾 Download Recommendations",
@ -231,8 +244,5 @@ def main():
mime="text/plain" mime="text/plain"
) )
except Exception as e:
st.error(f"❌ Error: {str(e)}")
if __name__ == "__main__": if __name__ == "__main__":
main() main()