Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,16 +53,22 @@ async def initialize(file_path, question):
|
|
53 |
|
54 |
if relevant_pages:
|
55 |
page_numbers = ', '.join(str(p) for p in sorted(relevant_pages))
|
56 |
-
|
57 |
else:
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
else:
|
60 |
return "Error: Unable to process the document. Please ensure the PDF file is valid."
|
61 |
|
62 |
# Define Gradio Interface
|
63 |
input_file = gr.File(label="Upload PDF File")
|
64 |
input_question = gr.Textbox(label="Ask about the document")
|
65 |
-
output_text = gr.Textbox(label="Relevant Pages")
|
66 |
|
67 |
async def pdf_qa(file, question):
|
68 |
if file is None:
|
|
|
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:
|