Spaces:
Sleeping
Sleeping
Download app.py from RozzaCreat/enabley-smart-search: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/spaces/RozzaCreat/enabley-smart-search/resolve/main/app.py
- Command line
-
hf download hf://spaces/RozzaCreat/enabley-smart-search/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RozzaCreat/enabley-smart-search/resolve/main/app.py
1.57 kB
| """ | |
| app.py β Streamlit search interface for Enabley RAG. | |
| Run: streamlit run app.py | |
| """ | |
| import streamlit as st | |
| from rag import RAGIndex | |
| st.set_page_config(page_title="π Enabley Smart Search", layout="wide") | |
| st.title("π Enabley Smart Search") | |
| st.caption("Semantic search over training course content β Hebrew / English / Russian") | |
| def load_index(): | |
| rag = RAGIndex() | |
| rag.load() | |
| return rag | |
| try: | |
| rag = load_index() | |
| st.success(f"Index loaded: {rag.index.ntotal} chunks indexed") | |
| except Exception as e: | |
| st.error(f"No index found. Run `python rag.py build` first.\n\nError: {e}") | |
| st.stop() | |
| query = st.text_input( | |
| "Search query / Χ©ΧΧΧΧͺΧͺ ΧΧΧ€ΧΧ©", | |
| placeholder="e.g. ΧΧͺΧ Χ ΧΧΧ¨ ΧΧ¨ΧΧ©ΧΧ? / what documents do I need?", | |
| ) | |
| top_k = st.slider("Number of results", 1, 10, 5) | |
| if query: | |
| results = rag.search(query, top_k=top_k) | |
| st.markdown(f"### Results for: *{query}*") | |
| for i, r in enumerate(results, 1): | |
| score = r["score"] | |
| source = r.get("source", "unknown") | |
| text = r["text"] | |
| # Color-code relevance | |
| if score > 0.85: | |
| badge = "π’" | |
| elif score > 0.70: | |
| badge = "π‘" | |
| else: | |
| badge = "π΄" | |
| with st.expander(f"{badge} Result {i} β score: {score:.3f} β [{source}]", expanded=(i <= 3)): | |
| st.markdown(text) | |
| if "slide" in r: | |
| st.caption(f"π Slide {r['slide']}") | |
| if "page" in r: | |
| st.caption(f"π Page {r['page']}") | |