日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
30行Python代碼就可以調用ChatGPTAPI總結論文的主要內容

閱讀論文可以說是我們的日常工作之一,論文的數(shù)量太多,我們如何快速閱讀歸納呢?自從ChatGPT出現(xiàn)以后,有很多閱讀論文的服務可以使用。其實使用ChatGPT API非常簡單,我們只用30行python代碼就可以在本地搭建一個自己的應用。

成都創(chuàng)新互聯(lián)公司長期為1000+客戶提供的網站建設服務,團隊從業(yè)經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網生態(tài)環(huán)境。為建甌企業(yè)提供專業(yè)的成都網站設計、網站建設,建甌網站改版等技術服務。擁有十載豐富建站經驗和眾多成功案例,為您定制開發(fā)。

使用 Python 和 ChatGPT API 總結論文的步驟很簡單:

  • 用于 PDF 處理的 PyPDF2 和用于與 GPT-3.5-turbo 接口的 OpenAI。
  • 使用 PyPDF2 打開并閱讀 PDF 文件。
  • 遍歷 PDF 文檔中的每一頁,提取文本。
  • 使用 GPT-3.5-turbo 為每個頁面的文本生成摘要。
  • 合并摘要并將最終摘要文本保存到文件中。
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)

搞定,關閉pdf文件,回收內存

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免費調用額度是有限的,這個方法一篇論文大概在0.2-0.5美元左右,根據(jù)論文長度會有變化

2、gpt4的API我沒測試,因為我還沒有申請到,并且看價格那個太貴了(貴20倍)我覺得不值,但是可以試試把論文的圖表一同傳過去,是不是會有更好效果(不確定)


當前文章:30行Python代碼就可以調用ChatGPTAPI總結論文的主要內容
當前路徑:http://www.5511xx.com/article/cdccgji.html