Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from langchain_huggingface import HuggingFaceEndpoint, HuggingFaceEmbeddings
|
|
9 |
from langchain.chains import ConversationalRetrievalChain
|
10 |
from langchain.memory import ConversationBufferMemory
|
11 |
from langchain.prompts import PromptTemplate
|
|
|
12 |
from pptx import Presentation
|
13 |
from io import BytesIO
|
14 |
import shutil
|
@@ -38,7 +39,7 @@ chat_history = []
|
|
38 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
39 |
PERSIST_DIRECTORY = tempfile.mkdtemp() # Use temporary directory for ChromaDB
|
40 |
|
41 |
-
# Custom prompt
|
42 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(
|
43 |
"""Given the following conversation and a follow-up question, rephrase the follow-up question to be a standalone question, incorporating relevant context from the conversation.
|
44 |
|
@@ -77,7 +78,10 @@ class PPTXLoader:
|
|
77 |
if hasattr(shape, "text") and shape.text:
|
78 |
text += shape.text + "\n"
|
79 |
if text.strip():
|
80 |
-
docs.append(
|
|
|
|
|
|
|
81 |
except Exception as e:
|
82 |
logger.error(f"Error loading PPTX {self.file_path}: {str(e)}")
|
83 |
return []
|
@@ -101,7 +105,7 @@ def load_documents(files):
|
|
101 |
documents.extend(loader.load())
|
102 |
elif file_path.endswith(".pptx"):
|
103 |
loader = PPTXLoader(file_path)
|
104 |
-
documents.extend(
|
105 |
except Exception as e:
|
106 |
logger.error(f"Error loading file {file_path}: {str(e)}")
|
107 |
continue
|
|
|
9 |
from langchain.chains import ConversationalRetrievalChain
|
10 |
from langchain.memory import ConversationBufferMemory
|
11 |
from langchain.prompts import PromptTemplate
|
12 |
+
from langchain_core.documents import Document
|
13 |
from pptx import Presentation
|
14 |
from io import BytesIO
|
15 |
import shutil
|
|
|
39 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
40 |
PERSIST_DIRECTORY = tempfile.mkdtemp() # Use temporary directory for ChromaDB
|
41 |
|
42 |
+
# Custom prompt templates
|
43 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(
|
44 |
"""Given the following conversation and a follow-up question, rephrase the follow-up question to be a standalone question, incorporating relevant context from the conversation.
|
45 |
|
|
|
78 |
if hasattr(shape, "text") and shape.text:
|
79 |
text += shape.text + "\n"
|
80 |
if text.strip():
|
81 |
+
docs.append(Document(
|
82 |
+
page_content=text,
|
83 |
+
metadata={"source": self.file_path, "slide": slide_num}
|
84 |
+
))
|
85 |
except Exception as e:
|
86 |
logger.error(f"Error loading PPTX {self.file_path}: {str(e)}")
|
87 |
return []
|
|
|
105 |
documents.extend(loader.load())
|
106 |
elif file_path.endswith(".pptx"):
|
107 |
loader = PPTXLoader(file_path)
|
108 |
+
documents.extend(loader.load())
|
109 |
except Exception as e:
|
110 |
logger.error(f"Error loading file {file_path}: {str(e)}")
|
111 |
continue
|