Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,21 +52,23 @@ async def initialize(file_path, question):
|
|
52 |
relevant_pages.add(i+1) # Add page number if phrase is found
|
53 |
|
54 |
if relevant_pages:
|
55 |
-
|
|
|
56 |
else:
|
57 |
-
source_str = "
|
58 |
|
59 |
# Create a clickable link for the document
|
60 |
file_name = os.path.basename(file_path)
|
61 |
source_link = f"[{file_name}](file://{os.path.abspath(file_path)})"
|
62 |
-
|
|
|
63 |
else:
|
64 |
return "Error: Unable to process the document. Please ensure the PDF file is valid."
|
65 |
|
66 |
# Define Gradio Interface
|
67 |
input_file = gr.File(label="Upload PDF File")
|
68 |
input_question = gr.Textbox(label="Ask about the document")
|
69 |
-
output_text = gr.Textbox(label="Answer
|
70 |
|
71 |
async def pdf_qa(file, question):
|
72 |
if file is None:
|
|
|
52 |
relevant_pages.add(i+1) # Add page number if phrase is found
|
53 |
|
54 |
if relevant_pages:
|
55 |
+
page_numbers = ', '.join(str(p) for p in sorted(relevant_pages))
|
56 |
+
source_str = f"Relevant pages: {page_numbers}"
|
57 |
else:
|
58 |
+
source_str = "Relevant pages: Not found in specific page"
|
59 |
|
60 |
# Create a clickable link for the document
|
61 |
file_name = os.path.basename(file_path)
|
62 |
source_link = f"[{file_name}](file://{os.path.abspath(file_path)})"
|
63 |
+
|
64 |
+
return f"Answer: {answer}\n{source_str}\n[Document: {source_link}]"
|
65 |
else:
|
66 |
return "Error: Unable to process the document. Please ensure the PDF file is valid."
|
67 |
|
68 |
# Define Gradio Interface
|
69 |
input_file = gr.File(label="Upload PDF File")
|
70 |
input_question = gr.Textbox(label="Ask about the document")
|
71 |
+
output_text = gr.Textbox(label="Answer and Relevant Pages")
|
72 |
|
73 |
async def pdf_qa(file, question):
|
74 |
if file is None:
|