Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,15 +84,16 @@ qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-base")
|
|
| 84 |
def document_qna_tool(pdf_path: str, question: str) -> str:
|
| 85 |
"""
|
| 86 |
A tool for answering questions based on the content of a PDF document.
|
| 87 |
-
|
| 88 |
Args:
|
| 89 |
pdf_path (str): Path to the local PDF file.
|
| 90 |
question (str): A natural language question to ask about the PDF content.
|
| 91 |
-
|
| 92 |
Returns:
|
| 93 |
str: Answer to the question based on the PDF's content.
|
| 94 |
"""
|
| 95 |
try:
|
|
|
|
|
|
|
|
|
|
| 96 |
# Step 1: Extract text from PDF
|
| 97 |
doc = fitz.open(pdf_path)
|
| 98 |
text_chunks = []
|
|
@@ -118,8 +119,7 @@ def document_qna_tool(pdf_path: str, question: str) -> str:
|
|
| 118 |
return f"Answer: {answer.strip()}"
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
-
return f"Error processing document QnA: {str(e)}"
|
| 122 |
-
|
| 123 |
|
| 124 |
# -------------------- Other Components --------------------
|
| 125 |
final_answer = FinalAnswerTool()
|
|
|
|
| 84 |
def document_qna_tool(pdf_path: str, question: str) -> str:
|
| 85 |
"""
|
| 86 |
A tool for answering questions based on the content of a PDF document.
|
|
|
|
| 87 |
Args:
|
| 88 |
pdf_path (str): Path to the local PDF file.
|
| 89 |
question (str): A natural language question to ask about the PDF content.
|
|
|
|
| 90 |
Returns:
|
| 91 |
str: Answer to the question based on the PDF's content.
|
| 92 |
"""
|
| 93 |
try:
|
| 94 |
+
if not os.path.exists(pdf_path):
|
| 95 |
+
return f"Error: File not found at {pdf_path}"
|
| 96 |
+
|
| 97 |
# Step 1: Extract text from PDF
|
| 98 |
doc = fitz.open(pdf_path)
|
| 99 |
text_chunks = []
|
|
|
|
| 119 |
return f"Answer: {answer.strip()}"
|
| 120 |
|
| 121 |
except Exception as e:
|
| 122 |
+
return f"Error processing document QnA: {type(e).__name__}: {str(e)}\n{traceback.format_exc()}"
|
|
|
|
| 123 |
|
| 124 |
# -------------------- Other Components --------------------
|
| 125 |
final_answer = FinalAnswerTool()
|