Spaces:
Runtime error
Runtime error
on1onmangoes
commited on
Commit
•
de392ff
1
Parent(s):
5c6a6e5
Update app.py
Browse files
app.py
CHANGED
@@ -81,6 +81,33 @@ def format_answer_string(answer: str):
|
|
81 |
|
82 |
return formatted_answer
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
# Function to handle PDF processing API call
|
86 |
def process_pdf(pdf_file):
|
@@ -195,16 +222,16 @@ with gr.Blocks(css=CSS) as demo:
|
|
195 |
outputs=pdf_output
|
196 |
)
|
197 |
|
198 |
-
with gr.Tab("Search"):
|
199 |
-
|
200 |
-
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
|
209 |
with gr.Tab("Answer with RAG"):
|
210 |
question_input = gr.Textbox(label="Enter Question for RAG")
|
|
|
81 |
|
82 |
return formatted_answer
|
83 |
|
84 |
+
def format_relevant_documents(relevant_docs: list):
|
85 |
+
"""
|
86 |
+
This function formats the relevant document metadata and content for readable output.
|
87 |
+
It extracts the heading, page number, and a snippet of the content from each document.
|
88 |
+
"""
|
89 |
+
formatted_docs = "Relevant Documents:\n\n"
|
90 |
+
|
91 |
+
for idx, (doc, score) in enumerate(relevant_docs):
|
92 |
+
# Extract the relevant metadata
|
93 |
+
heading = doc.metadata.get('heading', 'Unnamed Document')
|
94 |
+
page_number = int(doc.metadata.get('page_number', -1))
|
95 |
+
source = doc.metadata.get('source', 'Unknown Source')
|
96 |
+
confidence = round(score, 4) # Rounding the score for cleaner output
|
97 |
+
|
98 |
+
# Add the formatted details to the output string
|
99 |
+
formatted_docs += f"Document {idx + 1}:\n"
|
100 |
+
formatted_docs += f" - Heading: {heading}\n"
|
101 |
+
formatted_docs += f" - Page Number: {page_number}\n"
|
102 |
+
formatted_docs += f" - Source: {source}\n"
|
103 |
+
formatted_docs += f" - Confidence Score: {confidence}\n"
|
104 |
+
|
105 |
+
# Optionally include a snippet from the content
|
106 |
+
content_snippet = doc.page_content[:200] # Take the first 200 characters for preview
|
107 |
+
formatted_docs += f" - Content Snippet: {content_snippet}...\n\n"
|
108 |
+
|
109 |
+
return formatted_docs.strip()
|
110 |
+
|
111 |
|
112 |
# Function to handle PDF processing API call
|
113 |
def process_pdf(pdf_file):
|
|
|
222 |
outputs=pdf_output
|
223 |
)
|
224 |
|
225 |
+
# with gr.Tab("Search"):
|
226 |
+
# query_input = gr.Textbox(label="Enter Search Query")
|
227 |
+
# search_output = gr.Textbox(label="Search Confidence Result", interactive=False)
|
228 |
|
229 |
+
# search_button = gr.Button("Search")
|
230 |
+
# search_button.click(
|
231 |
+
# search_api,
|
232 |
+
# inputs=query_input,
|
233 |
+
# outputs=search_output
|
234 |
+
# )
|
235 |
|
236 |
with gr.Tab("Answer with RAG"):
|
237 |
question_input = gr.Textbox(label="Enter Question for RAG")
|