forked from mistralai/cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_and_retreive.py
40 lines (31 loc) · 1.05 KB
/
upload_and_retreive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import requests
from indexify import IndexifyClient
def download_pdf(url, save_path):
response = requests.get(url)
with open(save_path, 'wb') as f:
f.write(response.content)
print(f"PDF downloaded and saved to {save_path}")
def summarize_pdf(pdf_path):
client = IndexifyClient()
# Upload the PDF file
content_id = client.upload_file("pdf_summarizer", pdf_path)
# Wait for the extraction to complete
client.wait_for_extraction(content_id)
# Retrieve the summarized content
summary = client.get_extracted_content(
content_id=content_id,
graph_name="pdf_summarizer",
policy_name="text_to_summary"
)
return summary[0]['content'].decode('utf-8')
# Example usage
if __name__ == "__main__":
pdf_url = "https://arxiv.org/pdf/2310.06825.pdf"
pdf_path = "reference_document.pdf"
# Download the PDF
download_pdf(pdf_url, pdf_path)
# Summarize the PDF
summary = summarize_pdf(pdf_path)
print("Summary of the PDF:")
print(summary)