- Set up your environment
- Capture a web page screenshot
- Analyze the screenshot with IBM watsonx.ai
- Create a mortgage rate report
Build a mortgage rate analysis tool
1. Set up your environment
Install the required dependencies and set up your API keys.- Python
.env file with your API keys:
- IBM watsonx.ai API key and Project ID
- Browserbase API key
.env
Make sure to install Playwright dependencies after installation by running
playwright install in your terminal.2. Capture a web page screenshot
Use Browserbase to navigate to the Freddie Mac mortgage rates page and capture a screenshot of the rate information that’s embedded in an iframe:- Python
Python screenshot.py
3. Analyze the screenshot with IBM watsonx.ai
Now, use IBM watsonx.ai’s vision model to analyze the captured screenshot and extract the mortgage rate information:- Python
Python analyze.py
4. Create a mortgage rate report
Combine the screenshot capture and analysis steps into a complete solution that produces a nicely formatted report.- Python
Python mortgage_analysis.py
Expected output
The screenshot step writesfreddie_mac_rates.jpeg. The combined script prints Mortgage Rate Analysis: followed by the model response. Review the image alongside the response before using any extracted rate values.
Cleanup
The screenshot function closes the browser on success. If it fails earlier, release the session using Manage browser sessions. Delete the generatedfreddie_mac_rates.jpeg file and any local report copies when you no longer need them.
Next steps
With this foundation, you can build more advanced workflows:- Schedule regular rate checks and track trends over time
- Compare rates across multiple mortgage providers
- Create dashboards to monitor rate changes and predict future trends
- Fill out mortgage applications using extracted data
Best practices
- Handle dynamic content: Some websites load data asynchronously, so make sure content is fully loaded by adding wait times before capturing screenshots.
- Add error handling: Implement robust error handling for network issues and page structure changes.
- Secure your credentials: Never expose API keys in client-side code or public repositories.