Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -87,8 +87,16 @@ def embed_pdf(file, collection_name):
|
|
87 |
# Save the uploaded file
|
88 |
filename = file.name
|
89 |
file_path = os.path.join('./', filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
with open(file_path, 'wb') as f:
|
91 |
-
f.write(
|
92 |
|
93 |
# Checking filetype for document parsing
|
94 |
mime_type = mimetypes.guess_type(file_path)[0]
|
@@ -121,13 +129,15 @@ def retrieve_info(query):
|
|
121 |
# Rerank the top results
|
122 |
reranked_results = co.rerank(query=query, documents=top_docs, top_n=3, model='rerank-english-v2.0')
|
123 |
|
124 |
-
# Format the reranked results
|
125 |
formatted_results = []
|
126 |
for idx, r in enumerate(reranked_results):
|
127 |
formatted_result = {
|
128 |
"Document Rank": idx + 1,
|
129 |
-
"
|
130 |
-
"
|
|
|
|
|
131 |
"Relevance Score": f"{r.relevance_score:.2f}"
|
132 |
}
|
133 |
formatted_results.append(formatted_result)
|
|
|
87 |
# Save the uploaded file
|
88 |
filename = file.name
|
89 |
file_path = os.path.join('./', filename)
|
90 |
+
|
91 |
+
# Check if the file object has 'read' method
|
92 |
+
if hasattr(file, 'read'):
|
93 |
+
file_content = file.read()
|
94 |
+
else:
|
95 |
+
# Handle the case where 'read' method is not available
|
96 |
+
file_content = file.getvalue() # Assuming it's a NamedString or similar object
|
97 |
+
|
98 |
with open(file_path, 'wb') as f:
|
99 |
+
f.write(file_content)
|
100 |
|
101 |
# Checking filetype for document parsing
|
102 |
mime_type = mimetypes.guess_type(file_path)[0]
|
|
|
129 |
# Rerank the top results
|
130 |
reranked_results = co.rerank(query=query, documents=top_docs, top_n=3, model='rerank-english-v2.0')
|
131 |
|
132 |
+
# Format the reranked results according to the Article schema
|
133 |
formatted_results = []
|
134 |
for idx, r in enumerate(reranked_results):
|
135 |
formatted_result = {
|
136 |
"Document Rank": idx + 1,
|
137 |
+
"Title": r.document['title'],
|
138 |
+
"Content": r.document['content'],
|
139 |
+
"Author": r.document['author'],
|
140 |
+
"Publish Date": r.document['publishDate'],
|
141 |
"Relevance Score": f"{r.relevance_score:.2f}"
|
142 |
}
|
143 |
formatted_results.append(formatted_result)
|