Spaces:
Runtime error
Runtime error
feat: User can choose model
Browse files
app.py
CHANGED
|
@@ -67,10 +67,12 @@ def get_hf_llm():
|
|
| 67 |
if not hf_token:
|
| 68 |
return None
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
llm = HuggingFaceEndpoint(
|
| 71 |
huggingfacehub_api_token=hf_token,
|
| 72 |
-
repo_id=
|
| 73 |
-
# repo_id="meta-llama/Llama-3.2-3B-Instruct",
|
| 74 |
temperature=0.3,
|
| 75 |
max_new_tokens=512,
|
| 76 |
task="conversational"
|
|
@@ -203,16 +205,36 @@ def user_input(user_question, db):
|
|
| 203 |
# --- Main App ---
|
| 204 |
def main():
|
| 205 |
st.set_page_config(page_title="Chat PDF (Hugging Face)")
|
| 206 |
-
st.header("Chat with PDF using
|
| 207 |
|
| 208 |
# Initialize session state variables
|
| 209 |
if "faiss_db" not in st.session_state:
|
| 210 |
st.session_state.faiss_db = None
|
| 211 |
if "vector_store" not in st.session_state:
|
| 212 |
st.session_state.vector_store = None
|
|
|
|
|
|
|
| 213 |
|
| 214 |
with st.sidebar:
|
| 215 |
st.title("Menu:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
pdf_docs = st.file_uploader("Upload PDFs", accept_multiple_files=True)
|
| 217 |
|
| 218 |
if st.button("Process PDFs"):
|
|
|
|
| 67 |
if not hf_token:
|
| 68 |
return None
|
| 69 |
|
| 70 |
+
# Get model selection from session state
|
| 71 |
+
model_choice = st.session_state.get("selected_model", "mistralai/Mistral-7B-Instruct-v0.2")
|
| 72 |
+
|
| 73 |
llm = HuggingFaceEndpoint(
|
| 74 |
huggingfacehub_api_token=hf_token,
|
| 75 |
+
repo_id=model_choice,
|
|
|
|
| 76 |
temperature=0.3,
|
| 77 |
max_new_tokens=512,
|
| 78 |
task="conversational"
|
|
|
|
| 205 |
# --- Main App ---
|
| 206 |
def main():
|
| 207 |
st.set_page_config(page_title="Chat PDF (Hugging Face)")
|
| 208 |
+
st.header("Chat with PDF using Hugging Face Models")
|
| 209 |
|
| 210 |
# Initialize session state variables
|
| 211 |
if "faiss_db" not in st.session_state:
|
| 212 |
st.session_state.faiss_db = None
|
| 213 |
if "vector_store" not in st.session_state:
|
| 214 |
st.session_state.vector_store = None
|
| 215 |
+
if "selected_model" not in st.session_state:
|
| 216 |
+
st.session_state.selected_model = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 217 |
|
| 218 |
with st.sidebar:
|
| 219 |
st.title("Menu:")
|
| 220 |
+
|
| 221 |
+
# Model Selection Dropdown
|
| 222 |
+
model_options = {
|
| 223 |
+
"Mistral 7B": "mistralai/Mistral-7B-Instruct-v0.2",
|
| 224 |
+
"Llama 3.2 3B": "meta-llama/Llama-3.2-3B-Instruct"
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
selected_model_name = st.selectbox(
|
| 228 |
+
"Choose Model:",
|
| 229 |
+
options=list(model_options.keys()),
|
| 230 |
+
index=0
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
st.session_state.selected_model = model_options[selected_model_name]
|
| 234 |
+
st.caption(f"Selected: `{st.session_state.selected_model}`")
|
| 235 |
+
|
| 236 |
+
st.divider()
|
| 237 |
+
|
| 238 |
pdf_docs = st.file_uploader("Upload PDFs", accept_multiple_files=True)
|
| 239 |
|
| 240 |
if st.button("Process PDFs"):
|