Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views1 page

Multi-Stage GPT-3 Text Summarizer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Multi-Stage GPT-3 Text Summarizer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

mport openai

import os

def open_file(filepath):
with open(filepath, 'r', encoding='UTF-8')as infile:
return infile.read()

def save_file(filepath, content):


with open(filepath, 'w', encoding='UTF8') as outfile:
outfile.write(content)

openai.api_key = open_file("openaiapi.txt")

def gpt_3 (prompt):


response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt1,
temperature=1.0,
max_tokens=600,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
text = response['choices'][0]['text'].strip()
return text

word1= open_file('input.txt')

#summary chain 1
word2 = open_file('prompt.txt').replace('<<WORD>>', word1)
word3 = gpt_3(word2)
print('/n/n/ summary 1:', word3)
save_file('firstword.txt', word3)

#summary chain 2
word4 = open_file('prompt2.txt').replace('<<WORD1>>', word3)
word5 = gpt_3(word4)
print('/n/n/ summary 2:', word5)
save_file('secondword.txt', word5)

#summary chain 3
word6 = open_file('prompt3.txt').replace('<<WORD2>>', word5)
word7 = gpt_3(word6)
print('/n/n/ summary 3:', word7)
save_file('thirdword.txt', word7)

#summary chain 4
word8 = open_file('prompt4.txt').replace('<<WORD3>>', word7)
word9 = gpt_3(word8)
print('/n/n/ summary 4:', word9)
save_file('fourthword.txt', word9)

You might also like