This script uses GPT to read a web page and answer questions on it.
Method & Python Script
- Install VS Code: https://code.visualstudio.com or another IDE.
- In VS Code open a new terminal window by navigating to Terminal > New Terminal.
- Install Homebrew by pasting the following code into the terminal and pressing Enter:
- Install Python in the same way:
- Next, install the modules that the script needs (dependencies):
- Now, create a project folder and navigate to it in VS Code via File > Open Folder.
- Create a new Python file in VS Code via File > New File. Name it something like GPTreader.py
- Copy and paste the following script into GPTreader.py
- Replace
YOUR_OPENAI_API_KEY
with your own OpenAI API key (available via subscription from https://platform.openai.com). - Replace the
url
andquestion
texts with your own and save the file. - Run the script from the terminal with:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
pip3 install requests pytrends
# v.0.0.1
import openai
import requests
from bs4 import BeautifulSoup
# Set up OpenAI API credentials
openai.api_key = "YOUR_OPENAI_API_KEY"
# Define the web page URL and the question to ask
url = "https://radix.wiki"
question = "Are there any errors or inconsistencies in this text?"
# Scrape the web page HTML using BeautifulSoup
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
# Extract the text from the web page and concatenate it into a single string
text = " ".join([p.text for p in soup.find_all("p")])
# Use GPT to answer the question
response = openai.Completion.create(
engine="text-davinci-003",
prompt = f"Q: {question}\nContext: {text}\nA:",
temperature=0.5,
max_tokens=1024,
stop=None,
frequency_penalty=0,
presence_penalty=0,
)
# Print the answer
answer = response.choices[0].text.strip()
print(answer)
python3 GPTreader.py