Spaces:
Runtime error
Runtime error
Commit
·
b5fb503
1
Parent(s):
479cb43
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,19 +14,10 @@ from langchain import HuggingFaceHub
|
|
| 14 |
API_KEY = os.environ["API_KEY"]
|
| 15 |
|
| 16 |
# Create a temporary upload directory
|
| 17 |
-
upload_dir = tempfile.mkdtemp()
|
| 18 |
|
| 19 |
# Define global variables for loaders and index
|
| 20 |
index = None
|
| 21 |
|
| 22 |
-
def load_file(pdf_file, progress=gr.Progress()):
|
| 23 |
-
global index
|
| 24 |
-
uploaded_pdf_path = os.path.join(upload_dir, pdf_file.name)
|
| 25 |
-
pdf_loader = UnstructuredPDFLoader(uploaded_pdf_path)
|
| 26 |
-
index = VectorstoreIndexCreator(
|
| 27 |
-
embedding=HuggingFaceEmbeddings(),
|
| 28 |
-
text_splitter=CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 29 |
-
).from_loaders([pdf_loader])
|
| 30 |
|
| 31 |
def chat(message,history):
|
| 32 |
global index
|
|
@@ -43,7 +34,7 @@ def chat(message,history):
|
|
| 43 |
retriever=index.vectorstore.as_retriever(),
|
| 44 |
input_key="question")
|
| 45 |
# Perform question-answering on the uploaded PDF with the user's question
|
| 46 |
-
gpt_response = chain.run(message)
|
| 47 |
return gpt_response
|
| 48 |
|
| 49 |
|
|
@@ -77,8 +68,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 77 |
text = gr.Textbox(label="Status")
|
| 78 |
def load_file(pdf_file):
|
| 79 |
global index
|
| 80 |
-
|
| 81 |
-
pdf_loader = UnstructuredPDFLoader(uploaded_pdf_path)
|
| 82 |
index = VectorstoreIndexCreator(
|
| 83 |
embedding=HuggingFaceEmbeddings(),
|
| 84 |
text_splitter=CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
|
|
|
| 14 |
API_KEY = os.environ["API_KEY"]
|
| 15 |
|
| 16 |
# Create a temporary upload directory
|
|
|
|
| 17 |
|
| 18 |
# Define global variables for loaders and index
|
| 19 |
index = None
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def chat(message,history):
|
| 23 |
global index
|
|
|
|
| 34 |
retriever=index.vectorstore.as_retriever(),
|
| 35 |
input_key="question")
|
| 36 |
# Perform question-answering on the uploaded PDF with the user's question
|
| 37 |
+
gpt_response = chain.run("Please provide the context or topic related to the PDF document you'd like to discuss. You can also ask any specific questions you have in mind. "+ message)
|
| 38 |
return gpt_response
|
| 39 |
|
| 40 |
|
|
|
|
| 68 |
text = gr.Textbox(label="Status")
|
| 69 |
def load_file(pdf_file):
|
| 70 |
global index
|
| 71 |
+
pdf_loader = UnstructuredPDFLoader(pdf_file.name)
|
|
|
|
| 72 |
index = VectorstoreIndexCreator(
|
| 73 |
embedding=HuggingFaceEmbeddings(),
|
| 74 |
text_splitter=CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|