Spaces:
Sleeping
Sleeping
| import os | |
| import streamlit as st | |
| from rag import retrieve, ask_llm | |
| # ----------------------------- | |
| # Streamlit Page Config | |
| # ----------------------------- | |
| st.set_page_config( | |
| page_title="Only The Truth β Astrology Tutor", | |
| page_icon="πͺ", | |
| layout="wide" | |
| ) | |
| st.title("πͺ Only The Truth β Astrology Tutor") | |
| st.caption("Vedic Astrology β’ PDF-Based Knowledge β’ RAG Powered") | |
| # ----------------------------- | |
| # User Input | |
| # ----------------------------- | |
| query = st.text_input( | |
| "Ask your astrology question:", | |
| placeholder="Example: Explain how twins are analyzed using D60 chart" | |
| ) | |
| # ----------------------------- | |
| # Process Query | |
| # ----------------------------- | |
| if query: | |
| with st.spinner("π Searching ancient wisdom..."): | |
| contexts = retrieve(query) | |
| with st.spinner("π§ Interpreting charts..."): | |
| answer = ask_llm(query, contexts) | |
| # ----------------------------- | |
| # Answer Section | |
| # ----------------------------- | |
| st.subheader("πͺ Answer") | |
| st.markdown(answer) | |
| # ----------------------------- | |
| # Image Display Logic (STRICT) | |
| # ----------------------------- | |
| st.subheader("π Reference Diagrams") | |
| IMAGE_DIR = "data/images" | |
| image_found = False | |
| query_lower = query.lower() | |
| KEYWORDS = [ | |
| "chart", "diagram", "lagna", "horoscope", | |
| "d60", "sashtyamsa", "divisional", "birth chart" | |
| ] | |
| for c in contexts: | |
| text_lower = c["text"].lower() | |
| # Only show images if BOTH query & chunk indicate diagram relevance | |
| if not any(k in query_lower for k in KEYWORDS): | |
| continue | |
| if not any(k in text_lower for k in KEYWORDS): | |
| continue | |
| for img in c.get("images", []): | |
| img_path = os.path.join(IMAGE_DIR, img) | |
| if os.path.exists(img_path): | |
| st.image( | |
| img_path, | |
| caption=f"{c['source']} β page {c['page']}", | |
| use_container_width=True | |
| ) | |
| image_found = True | |
| if not image_found: | |
| st.info("βΉ No relevant diagrams found in the reference material.") | |
| # ----------------------------- | |
| # Footer | |
| # ----------------------------- | |
| st.markdown("---") | |
| st.caption("Built with FAISS β’ SentenceTransformers β’ Groq β’ Streamlit") | |