Spaces:
Sleeping
Sleeping
File size: 2,329 Bytes
709c859 |
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 |
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")
|