掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
閱讀論文可以說是我們的日常工作之一,論文的數(shù)量太多,我們?nèi)绾慰焖匍喿x歸納呢?自從ChatGPT出現(xiàn)以后,有很多閱讀論文的服務(wù)可以使用。其實使用ChatGPT API非常簡單,我們只用30行python代碼就可以在本地搭建一個自己的應(yīng)用。

成都創(chuàng)新互聯(lián)公司長期為1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為建甌企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè),建甌網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
使用 Python 和 ChatGPT API 總結(jié)論文的步驟很簡單:
import PyPDF2
import openai
pdf_summary_text = ""
解析pdf
pdf_file_path = "./pdfs/paper.pdf"
pdf_file = open(pdf_file_path, 'rb')
pdf_reader = PyPDF2.PdfReader(pdf_file)
獲取每一頁的文本:
for page_num in range(len(pdf_reader.pages)):
page_text = pdf_reader.pages[page_num].extract_text().lower()
使用openai的api進行匯總
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful research assistant."},
{"role": "user", "content": f"Summarize this: {page_text}"},
],
)
page_summary = response["choices"][0]["message"]["content"]
合并摘要
pdf_summary_text += page_summary + "\n"
pdf_summary_file = pdf_file_path.replace(os.path.splitext(pdf_file_path)[1], "_summary.txt")
with open(pdf_summary_file, "w+") as file:
file.write(pdf_summary_text)
搞定,關(guān)閉pdf文件,回收內(nèi)存
pdf_file.close()
完整代碼如下:
import os
import PyPDF2
import re
import openai
# Here I assume you are on a Jupiter Notebook and download the paper directly from the URL
!curl -o paper.pdf https://arxiv.org/pdf/2301.00810v3.pdf?utm_source=pocket_saves
# Set the string that will contain the summary
pdf_summary_text = ""
# Open the PDF file
pdf_file_path = "paper.pdf"
# Read the PDF file using PyPDF2
pdf_file = open(pdf_file_path, 'rb')
pdf_reader = PyPDF2.PdfReader(pdf_file)
# Loop through all the pages in the PDF file
for page_num in range(len(pdf_reader.pages)):
# Extract the text from the page
page_text = pdf_reader.pages[page_num].extract_text().lower()
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful research assistant."},
{"role": "user", "content": f"Summarize this: {page_text}"},
],
)
page_summary = response["choices"][0]["message"]["content"]
pdf_summary_text+=page_summary + "\n"
pdf_summary_file = pdf_file_path.replace(os.path.splitext(pdf_file_path)[1], "_summary.txt")
with open(pdf_summary_file, "w+") as file:
file.write(pdf_summary_text)
pdf_file.close()
with open(pdf_summary_file, "r") as file:
print(file.read())
需要說明的是2個事情:
1、openai的API免費調(diào)用額度是有限的,這個方法一篇論文大概在0.2-0.5美元左右,根據(jù)論文長度會有變化
2、gpt4的API我沒測試,因為我還沒有申請到,并且看價格那個太貴了(貴20倍)我覺得不值,但是可以試試把論文的圖表一同傳過去,是不是會有更好效果(不確定)

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流