File size: 3,771 Bytes
9142902 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# ---------------------------------------------------
# πΎ Project Samarth β Intelligent Q&A System
# ---------------------------------------------------
import sys, os
import streamlit as st
# β
Ensure Python finds your project modules
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")
from query_engine.parser import parse_query
from query_engine.logic_engine import run_query
from answer_generator.citation_manager import get_source
# ---------------------------------------------------
# βοΈ Streamlit Page Setup
# ---------------------------------------------------
st.set_page_config(page_title="πΎ Project Samarth β Intelligent Q&A", layout="centered")
# β
Load custom CSS
try:
st.markdown("<style>" + open("ui/style.css").read() + "</style>", unsafe_allow_html=True)
except Exception as e:
st.warning("β οΈ Could not load CSS file. Using default Streamlit styling.")
# ---------------------------------------------------
# π§ Title and Info
# ---------------------------------------------------
st.title("πΎ Project Samarth β Intelligent Q&A System")
st.caption("Ask intelligent, data-driven questions about agriculture and climate using live datasets from data.gov.in.")
# ---------------------------------------------------
# βοΈ Input Section
# ---------------------------------------------------
query = st.text_area(
"π§ Ask your question:",
height=100,
placeholder="Example: Compare rainfall and rice production in Andaman and Nicobar Islands and Andhra Pradesh for the last 5 years"
)
# ---------------------------------------------------
# π Analyze Button Logic
# ---------------------------------------------------
if st.button("π Analyze"):
if not query.strip():
st.warning("Please enter a valid question.")
else:
with st.spinner("Analyzing your question..."):
try:
# 1οΈβ£ Parse user query
parsed_query = parse_query(query)
# 2οΈβ£ Run analysis logic
result = run_query(parsed_query)
# 3οΈβ£ Get citation source
source = get_source(parsed_query.get("query_type"))
# 4οΈβ£ Display structured results
st.markdown("---")
st.markdown("### π Result Summary")
if "error" in result:
st.error(result["error"])
elif "message" in result:
st.info(result["message"])
else:
states = parsed_query.get("states", [])
crop = parsed_query.get("crop", "")
st.markdown(f"### π Analysis for {', '.join(states)} β Crop: {crop.title()}")
# π§οΈ Rainfall Summary
if "rainfall_summary" in result:
st.markdown("#### π§οΈ Average Rainfall (mm):")
for state, value in result["rainfall_summary"].items():
st.markdown(f"- **{state.title()}**: `{value}` mm")
# πΎ Production Summary
if "production_summary" in result:
st.markdown("#### πΎ Total Production (tonnes):")
for state, value in result["production_summary"].items():
st.markdown(f"- **{state.title()}**: `{int(value)}` tonnes")
st.markdown("---")
st.markdown(f"π **Data Source:** {source}")
st.caption("Developed for Project Samarth β Integrating Agriculture & Climate Data π¦οΈπΎ")
except Exception as e:
st.error(f"β Something went wrong: {e}")
|