Spaces:
Sleeping
Sleeping
Commit ·
8c1e6b5
1
Parent(s): 903ba06
updated UI for question input bar
Browse files- src/__pycache__/qa_prompts.cpython-311.pyc +0 -0
- src/data_index/index.faiss +0 -0
- src/data_index/index.pkl +0 -0
- src/qa_prompts.py +18 -2
- src/streamlit_app.py +6 -22
src/__pycache__/qa_prompts.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/qa_prompts.cpython-311.pyc and b/src/__pycache__/qa_prompts.cpython-311.pyc differ
|
|
|
src/data_index/index.faiss
CHANGED
|
Binary files a/src/data_index/index.faiss and b/src/data_index/index.faiss differ
|
|
|
src/data_index/index.pkl
CHANGED
|
Binary files a/src/data_index/index.pkl and b/src/data_index/index.pkl differ
|
|
|
src/qa_prompts.py
CHANGED
|
@@ -1,9 +1,25 @@
|
|
| 1 |
PROMPT_TMPL = """You are a helpful chatbot that answers questions about the candidate's profile for recruiters.
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
Context:
|
| 5 |
{context}
|
| 6 |
|
| 7 |
Question: {question}
|
| 8 |
|
| 9 |
-
Answer:"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
PROMPT_TMPL = """You are a helpful chatbot that answers questions about the candidate's profile for recruiters.
|
| 2 |
+
|
| 3 |
+
- If the user greets you (e.g., "hi", "hello", "hey", "goodbye"), respond politely and naturally.
|
| 4 |
+
- If the question is about the candidate's profile, use ONLY the provided context to answer.
|
| 5 |
+
- If the answer is not in the context, say you don't know.
|
| 6 |
+
- Be concise and factual.
|
| 7 |
|
| 8 |
Context:
|
| 9 |
{context}
|
| 10 |
|
| 11 |
Question: {question}
|
| 12 |
|
| 13 |
+
Answer:"""
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# PROMPT_TMPL = """You are a helpful chatbot that answers questions about the candidate's profile for recruiters.
|
| 18 |
+
# Use ONLY the provided context. If the answer is not in the context, say you don't know. Be concise and factual.
|
| 19 |
+
|
| 20 |
+
# Context:
|
| 21 |
+
# {context}
|
| 22 |
+
|
| 23 |
+
# Question: {question}
|
| 24 |
+
|
| 25 |
+
# Answer:"""
|
src/streamlit_app.py
CHANGED
|
@@ -25,7 +25,7 @@ ROOT_DIR = Path(__file__).parent
|
|
| 25 |
INDEX_DIR = Path(f"{ROOT_DIR}/data_index")
|
| 26 |
|
| 27 |
|
| 28 |
-
###### run ingest.py ######
|
| 29 |
|
| 30 |
if not INDEX_DIR.exists():
|
| 31 |
with st.spinner("Index not found. Building FAISS index (first run)…"):
|
|
@@ -82,7 +82,7 @@ def build_chain_gemini(retriever, _llm_repo, _max_new, _temp, _show_sources):
|
|
| 82 |
# ========================= Streamlit UI =========================
|
| 83 |
st.set_page_config(page_title="Maheen's Profile Chatbot", page_icon="💬", layout="centered")
|
| 84 |
st.title("Maheen's Profile Chatbot")
|
| 85 |
-
st.caption("
|
| 86 |
|
| 87 |
# Sidebar settings
|
| 88 |
st.sidebar.header("Settings")
|
|
@@ -90,28 +90,19 @@ hf_token = HF_API_TOKEN
|
|
| 90 |
if not hf_token:
|
| 91 |
st.sidebar.warning("HUGGINGFACEHUB_API_TOKEN is not set. Set it in your shell before running the app.")
|
| 92 |
|
| 93 |
-
# store_dir = st.sidebar.text_input("FAISS store path", value=INDEX_DIR)
|
| 94 |
-
|
| 95 |
-
# llm_repo_id = st.sidebar.text_input("LLM repo (HF)", value=LLM_MODEL_NAME)
|
| 96 |
-
# embed_repo_id = st.sidebar.text_input("Embedding model (HF)", value=EMBED_MODEL_NAME)
|
| 97 |
-
|
| 98 |
# Display model names as text (read-only)
|
| 99 |
st.sidebar.markdown(f"**Embedding Model:** `{EMBED_MODEL_NAME}`")
|
| 100 |
st.sidebar.markdown(f"**Chat Model:** `{LLM_MODEL_NAME}`")
|
| 101 |
|
| 102 |
-
|
| 103 |
-
# k = st.sidebar.number_input("Top-k retrieved chunks", min_value=1, max_value=20, value=4, step=1)
|
| 104 |
k = 4
|
| 105 |
-
# max_new_tokens = st.sidebar.number_input("Max new tokens", min_value=64, max_value=2048, value=512, step=64)
|
| 106 |
max_new_tokens = 512
|
| 107 |
-
# temperature = st.sidebar.slider("Temperature", min_value=0.0, max_value=1.0, value=0.1, step=0.05)
|
| 108 |
temperature = 0.1
|
| 109 |
-
# show_sources = st.sidebar.checkbox("Show sources", value=False)
|
| 110 |
show_sources = False
|
| 111 |
|
| 112 |
|
| 113 |
###################
|
| 114 |
|
|
|
|
| 115 |
# Session state for chat history
|
| 116 |
if "history" not in st.session_state:
|
| 117 |
st.session_state.history = [] # list of (user, assistant, sources)
|
|
@@ -148,14 +139,9 @@ def render_sources(docs):
|
|
| 148 |
st.write(d.page_content[:1500] + ("…" if len(d.page_content) > 1500 else ""))
|
| 149 |
|
| 150 |
# --- Chat input with Enter submit ---
|
| 151 |
-
|
| 152 |
-
user_input = st.text_input(
|
| 153 |
-
"Ask about my profile:",
|
| 154 |
-
placeholder="e.g., What are your key projects?"
|
| 155 |
-
)
|
| 156 |
-
submitted = st.form_submit_button("Ask")
|
| 157 |
|
| 158 |
-
if
|
| 159 |
with st.spinner("Thinking…"):
|
| 160 |
try:
|
| 161 |
res = chain.invoke({"query": user_input.strip()})
|
|
@@ -168,7 +154,7 @@ if submitted and user_input.strip():
|
|
| 168 |
answer, sources = f"[error] {e}", []
|
| 169 |
st.session_state.history.append((user_input.strip(), answer, sources))
|
| 170 |
|
| 171 |
-
# Display history
|
| 172 |
for q, a, srcs in st.session_state.history:
|
| 173 |
st.markdown(f"**You:** {q}")
|
| 174 |
st.markdown(f"**Assistant:** {a}")
|
|
@@ -176,5 +162,3 @@ for q, a, srcs in st.session_state.history:
|
|
| 176 |
render_sources(srcs)
|
| 177 |
st.markdown("---")
|
| 178 |
|
| 179 |
-
# Footer
|
| 180 |
-
# st.caption("Enter submits. Datastore path fixed from code/env. Models shown read-only.")
|
|
|
|
| 25 |
INDEX_DIR = Path(f"{ROOT_DIR}/data_index")
|
| 26 |
|
| 27 |
|
| 28 |
+
###### run ingest.py (to be run locally) ######
|
| 29 |
|
| 30 |
if not INDEX_DIR.exists():
|
| 31 |
with st.spinner("Index not found. Building FAISS index (first run)…"):
|
|
|
|
| 82 |
# ========================= Streamlit UI =========================
|
| 83 |
st.set_page_config(page_title="Maheen's Profile Chatbot", page_icon="💬", layout="centered")
|
| 84 |
st.title("Maheen's Profile Chatbot")
|
| 85 |
+
st.caption("Want to know about my skills and experience? Enter your question below 👇")
|
| 86 |
|
| 87 |
# Sidebar settings
|
| 88 |
st.sidebar.header("Settings")
|
|
|
|
| 90 |
if not hf_token:
|
| 91 |
st.sidebar.warning("HUGGINGFACEHUB_API_TOKEN is not set. Set it in your shell before running the app.")
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
# Display model names as text (read-only)
|
| 94 |
st.sidebar.markdown(f"**Embedding Model:** `{EMBED_MODEL_NAME}`")
|
| 95 |
st.sidebar.markdown(f"**Chat Model:** `{LLM_MODEL_NAME}`")
|
| 96 |
|
|
|
|
|
|
|
| 97 |
k = 4
|
|
|
|
| 98 |
max_new_tokens = 512
|
|
|
|
| 99 |
temperature = 0.1
|
|
|
|
| 100 |
show_sources = False
|
| 101 |
|
| 102 |
|
| 103 |
###################
|
| 104 |
|
| 105 |
+
|
| 106 |
# Session state for chat history
|
| 107 |
if "history" not in st.session_state:
|
| 108 |
st.session_state.history = [] # list of (user, assistant, sources)
|
|
|
|
| 139 |
st.write(d.page_content[:1500] + ("…" if len(d.page_content) > 1500 else ""))
|
| 140 |
|
| 141 |
# --- Chat input with Enter submit ---
|
| 142 |
+
user_input = st.chat_input("e.g. Tell me about your experience as AI Engineer")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
+
if user_input:
|
| 145 |
with st.spinner("Thinking…"):
|
| 146 |
try:
|
| 147 |
res = chain.invoke({"query": user_input.strip()})
|
|
|
|
| 154 |
answer, sources = f"[error] {e}", []
|
| 155 |
st.session_state.history.append((user_input.strip(), answer, sources))
|
| 156 |
|
| 157 |
+
# Display history in logs
|
| 158 |
for q, a, srcs in st.session_state.history:
|
| 159 |
st.markdown(f"**You:** {q}")
|
| 160 |
st.markdown(f"**Assistant:** {a}")
|
|
|
|
| 162 |
render_sources(srcs)
|
| 163 |
st.markdown("---")
|
| 164 |
|
|
|
|
|
|