Spaces:
Runtime error
Runtime error
File size: 4,309 Bytes
f3f062d ed97b4c bf13fdb f3f062d f37711c f3f062d 644c5e0 f3f062d f37711c f3f062d f37711c f3f062d f37711c 2120fcf f3f062d 2120fcf f3f062d 2120fcf f3f062d f37711c 2120fcf f37711c f3f062d f37711c f3f062d f37711c 2120fcf f3f062d 2120fcf f3f062d 2120fcf f3f062d 2120fcf f3f062d 2120fcf f37711c | 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 93 94 95 96 97 98 99 100 101 102 103 104 105 | 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)")
@st.cache_resource
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}")
|