This script uses GPT to read a web page and answer questions on it.
THE MEME STUDIO | Web3 Marketing Agency
Crypto Content Wizards. Degens, you found your Web3 Marketing Agency! Experienced in helping DAOs, DeFi, P2E, NFT, and Metaverse projects with 3D Animations, Memes and more! The Meme Studio is your Web3 Agency.
www.thememestudio.com
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_KEYwith your own OpenAI API key (available via subscription from https://platform.openai.com). - Replace the
urlandquestiontexts 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 pythonpip3 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