Meta Description: Learn how to set up JupyterLab, activate your Conda environment, connect to OpenAI’s API, and build your first web-scraping AI project. Perfect for data science beginners!
Starting your first project can sometimes feel like a long road with little instant gratification. But don’t worry — that’s about to change! Today, we’re diving into a fun, hands-on project that will give you a real taste of working with AI and Python in JupyterLab.
Setting Up a Fresh Environment
Before we jump into coding, let’s make sure your setup is clean and ready. If you already have JupyterLab or Anaconda running, go ahead and close them. Then, open a fresh terminal (on Mac) or Anaconda prompt (on Windows).
Navigate to your project folder and activate your environment:
conda activate LMS
Once activated, you’re ready to launch JupyterLab:
jupyter lab
After a few seconds, JupyterLab should open in your browser. It’s an interactive coding environment that data scientists love for experimentation, prototyping, and visualization. You’ll see the file browser on the left, showing directories for each week or section of your course.
Why JupyterLab Is So Powerful
JupyterLab is one of the most flexible environments for data analysis and machine learning. You can run code cell by cell, visualize output instantly, and mix text, images, and graphs in one notebook. It’s great for experimentation — just remember that it uses global variables extensively, which isn’t ideal for production code but is perfect for research and learning.
If this is your first time using JupyterLab, you can open the built-in guide provided in your course files. It teaches you basic commands like running a cell with Shift + Enter and shows how to navigate through your notebook efficiently.
Day One Project: Build a Web Scraping and Summarization Tool
Now for the fun part — your first AI project! You’ll build a Python program that can visit any webpage, scrape its content, and automatically summarize it. Think of it as your own personal Reader’s Digest web browser.
Step 1: Load Your API Key
Before you can connect to OpenAI’s GPT models, you need to load your API key from your .env
file:
from dotenv import load_dotenv
load_dotenv()
If you see a message saying “API key found and looks good so far,” you’re ready to go. If not, check your troubleshooting notebook or verify your environment setup.
Step 2: Connect to OpenAI
Once your environment is ready, you can connect to the OpenAI API to interact with GPT models and process natural language data.
from openai import OpenAI
openai = OpenAI(api_key=API_KEY)
Step 3: Create a Web Scraping Class
Next, define a Website
class that can scrape a webpage, extract the title and text, and remove unnecessary scripts, images, and styles. This is where the BeautifulSoup library shines:
from bs4 import BeautifulSoup
import requests
class Website:
def __init__(self, url):
self.url = url
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
self.title = soup.title.string if soup.title else "No Title"
for script in soup(["script", "style", "img", "input"]):
script.extract()
self.text = soup.get_text()
Step 4: Test Your Class
Let’s test it on a sample webpage — for example, your own portfolio site:
my_site = Website("https://yourwebsite.com")
print(my_site.title)
print(my_site.text[:500])
If everything runs smoothly, you’ll see the website’s title and some text extracted directly from the page. Congratulations — you’ve just built a basic web scraping tool!
Troubleshooting Tips
If something goes wrong, don’t panic. Most issues happen because the Conda environment wasn’t activated correctly or the API key wasn’t loaded. Check your troubleshooting.ipynb
notebook or verify your .env
file. You can also reach out to your course instructor via email or LinkedIn for support.
What’s Next?
This is just the beginning. In future lessons, you’ll learn how to process your scraped data with GPT, generate summaries, and even build full AI-powered applications. By the end of the course, you’ll know how to deploy your code from JupyterLab into a production-ready environment.
Pro Tip: Always experiment freely in JupyterLab. It’s the perfect space to learn, test ideas, and develop confidence as an AI engineer or data scientist.
Conclusion
By setting up your environment and running your first project, you’ve taken an important step into the world of AI and data science. You’ve learned how to use JupyterLab, connect to OpenAI, and build a simple yet powerful web scraping project. Keep going — the more you practice, the more intuitive it will become.
Stay tuned for the next lesson, where we’ll explore text summarization and GPT-powered automation in more depth!