I really don't know how to solve this issue after ask GPT many times #1197
Unanswered
gettingalot
asked this question in
Q&A
Replies: 1 comment
-
You seem to be using version 0.28's code on a more recent version of OpenAI. Either adapt your code to the most recent SDK version or downgrade to 0.28 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
context: i have tried different ways of getting latest version etc.
:( still not getting it right
import PyPDF2
import openai
from pptx import Presentation
title = "openai"
version = "1.13.2" # x-release-please-version
Step 1: Extract text from PDF for all pages
def extract_text_from_pdf(pdf_path):
text = ""
with open(pdf_path, 'rb') as file:
reader = PyPDF2.PdfReader(file)
for page in reader.pages:
text += page.extract_text()
return text
Step 2: Summarize text using OpenAI API
def summarize_text(text):
# Set up OpenAI API
openai.api_key = 'API_File'
# Make the API call to summarize
response = openai.Completion.create(
model="text-davinci-003",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": text},
]
)
return response['choices'][0]['message']['content']
Step 3: Create PowerPoint slides
def create_ppt(summaries):
prs = Presentation()
slide_layout = prs.slide_layouts[1] # Choose slide layout (e.g., Title and Content)
for summary in summaries:
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
content = slide.placeholders[1]
title.text = "Summary"
content.text = summary
prs.save("summary_slides.pptx")
Main function
def main(pdf_path):
# Step 1: Extract text from PDF for all pages
pdf_text = extract_text_from_pdf(pdf_path)
if name == "main":
pdf_path = r"C:\Users\Chao\Desktop\2023-gore-street-energy-storage-fund-esg-and-sunstainability-report.pdf"
main(pdf_path)
Beta Was this translation helpful? Give feedback.
All reactions