Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,6 @@ This script uses the LangChain Language Model API to answer questions using Retr
|
|
| 4 |
and FAISS vector stores. It also uses the Mistral huggingface inference endpoint to
|
| 5 |
generate responses.
|
| 6 |
"""
|
| 7 |
-
import os
|
| 8 |
-
import streamlit as st
|
| 9 |
-
from dotenv import load_dotenv
|
| 10 |
-
from PyPDF2 import PdfReader
|
| 11 |
-
from langchain.text_splitter import CharacterTextSplitter
|
| 12 |
-
from langchain.embeddings import HuggingFaceBgeEmbeddings
|
| 13 |
-
from langchain.vectorstores import FAISS
|
| 14 |
-
from langchain.chat_models import ChatOpenAI
|
| 15 |
-
from langchain.memory import ConversationBufferMemory
|
| 16 |
-
from langchain.chains import ConversationalRetrievalChain
|
| 17 |
-
from htmlTemplates import css, bot_template, user_template
|
| 18 |
-
from langchain.llms import HuggingFaceHub
|
| 19 |
|
| 20 |
import os
|
| 21 |
import streamlit as st
|
|
@@ -106,6 +94,18 @@ def main():
|
|
| 106 |
if user_question:
|
| 107 |
handle_userinput(user_question)
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
with st.sidebar:
|
| 110 |
st.subheader("Your documents")
|
| 111 |
pdf_docs = st.file_uploader(
|
|
|
|
| 4 |
and FAISS vector stores. It also uses the Mistral huggingface inference endpoint to
|
| 5 |
generate responses.
|
| 6 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
import os
|
| 9 |
import streamlit as st
|
|
|
|
| 94 |
if user_question:
|
| 95 |
handle_userinput(user_question)
|
| 96 |
|
| 97 |
+
# Add Hugging Face token input
|
| 98 |
+
huggingface_token = st.text_input("Enter your Hugging Face API token:", type="password")
|
| 99 |
+
if huggingface_token:
|
| 100 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = huggingface_token
|
| 101 |
+
|
| 102 |
+
user_question = st.text_input("Ask a question about your documents:")
|
| 103 |
+
if user_question:
|
| 104 |
+
if not huggingface_token:
|
| 105 |
+
st.error("Please enter your Hugging Face API token to proceed.")
|
| 106 |
+
else:
|
| 107 |
+
handle_userinput(user_question)
|
| 108 |
+
|
| 109 |
with st.sidebar:
|
| 110 |
st.subheader("Your documents")
|
| 111 |
pdf_docs = st.file_uploader(
|