Spaces:
Runtime error
Runtime error
Download src/streamlit_app.py from ResumeScreening/resume-screening-rag: direct link, hf CLI and curl.
- Browser
- Download file 4.31 kB
-
https://huggingface.co/spaces/ResumeScreening/resume-screening-rag/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/ResumeScreening/resume-screening-rag/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/ResumeScreening/resume-screening-rag/resolve/main/src/streamlit_app.py
4.31 kB
| from __future__ import annotations | |
| import streamlit as st | |
| import config | |
| from embeddings import embed_texts, embed_query, embedding_dim | |
| from vector_store import PineconeVectorStore | |
| from ingest import build_vectors_for_pdf | |
| from search import search_resumes | |
| NAMESPACE = "resumes" | |
| st.set_page_config(page_title="Resume Screening (RAG)", layout="wide") | |
| st.title("Resume Screening System (RAG)") | |
| def get_vector_store(): | |
| dim = embedding_dim(config.EMBED_MODEL_NAME) | |
| return PineconeVectorStore( | |
| api_key=config.PINECONE_API_KEY, | |
| index_name=config.PINECONE_INDEX_NAME, | |
| dimension=dim, | |
| cloud=config.PINECONE_CLOUD, | |
| region=config.PINECONE_REGION, | |
| ) | |
| vs = get_vector_store() | |
| tab1, tab2, tab3 = st.tabs(["Upload & Ingest", "Search", "Admin"]) | |
| with tab1: | |
| st.subheader("Upload & Ingest PDF Resumes") | |
| uploaded_file = st.file_uploader("Upload a PDF resume", type=["pdf"]) | |
| colA, colB, colC = st.columns(3) | |
| with colA: | |
| chunk_size = st.number_input("Chunk size (chars)", min_value=200, max_value=4000, value=config.CHUNK_SIZE, step=100) | |
| with colB: | |
| overlap = st.number_input("Overlap (chars)", min_value=0, max_value=1000, value=config.CHUNK_OVERLAP, step=50) | |
| with colC: | |
| namespace = st.text_input("Namespace", value=NAMESPACE) | |
| if st.button("Ingest", type="primary", disabled=not uploaded_file): | |
| try: | |
| with st.spinner("Processing and uploading to Pinecone..."): | |
| vectors = build_vectors_for_pdf( | |
| pdf_bytes=uploaded_file.read(), | |
| filename=uploaded_file.name, | |
| embed_fn=lambda texts: embed_texts(texts, model_name=config.EMBED_MODEL_NAME), | |
| chunk_size=int(chunk_size), | |
| overlap=int(overlap), | |
| ) | |
| vs.upsert(vectors=vectors, namespace=namespace) | |
| st.success(f"Done. Upserted {len(vectors)} chunks into namespace '{namespace}'.") | |
| except Exception as e: | |
| st.error(f"Ingest failed: {e}") | |
| with tab2: | |
| st.subheader("Search candidates") | |
| namespace = st.text_input("Namespace to search", value=NAMESPACE, key="search_namespace") | |
| query = st.text_input("Enter a keyword or query", placeholder="e.g., Python SQL ETL 3 years, machine learning internship") | |
| col1, col2 = st.columns([1, 1]) | |
| with col1: | |
| top_k = st.slider("Top K results", min_value=3, max_value=20, value=config.TOP_K, step=1) | |
| with col2: | |
| min_score = st.slider("Minimum similarity score", min_value=0.0, max_value=1.0, value=0.2, step=0.05) | |
| if st.button("Search", type="primary", disabled=not query.strip()): | |
| try: | |
| with st.spinner("Searching..."): | |
| results = search_resumes( | |
| query=query.strip(), | |
| embed_query_fn=lambda q: embed_query(q, model_name=config.EMBED_MODEL_NAME), | |
| vector_store=vs, | |
| top_k=int(top_k), | |
| namespace=namespace, | |
| ) | |
| results = [r for r in results if r["score"] >= float(min_score)] | |
| if not results: | |
| st.warning("No matches found (try lowering minimum score or ingest more resumes).") | |
| else: | |
| st.write(f"Found {len(results)} matches:") | |
| for r in results: | |
| with st.container(border=True): | |
| st.markdown( | |
| f"**{r['filename']}** \n" | |
| f"Score: `{r['score']:.3f}` | Page: `{r['page']}` | Chunk: `{r['chunk_index']}`" | |
| ) | |
| st.write(r["text"][:1200] + ("..." if len(r["text"]) > 1200 else "")) | |
| except Exception as e: | |
| st.error(f"Search failed: {e}") | |
| with tab3: | |
| st.subheader("Admin") | |
| namespace = st.text_input("Namespace to clear", value=NAMESPACE, key="admin_namespace") | |
| st.warning("This will delete ALL vectors in the namespace.") | |
| if st.button("Delete namespace vectors", type="secondary"): | |
| try: | |
| vs.delete_namespace(namespace=namespace) | |
| st.success(f"Deleted all vectors in namespace '{namespace}'.") | |
| except Exception as e: | |
| st.error(f"Delete failed: {e}") | |