Navigating building AI products: A Step-by-Step Guide

Robin Kiplang'at
fourbic
Published in
3 min readSep 26, 2023
Photo by Gerard Siderius on Unsplash

Introduction

Imagine having to go through a stack of lab reports, each filled with complex medical jargon and lengthy explanations. It’s a daunting task, isn’t it? But what if we could use Artificial Intelligence (AI) to simplify this process?

In this blog post, I’ll guide you on how to create a tool that uses AI to read and summarize lab reports. This tool uses two key components: Langchain and OpenAI.

What are Langchain and OpenAI?

Before we dive into the how-to, let’s understand what Langchain and OpenAI are. Langchain is a library that allows us to combine different AI models to perform complex tasks. Think of Langchain as a master chef who knows how to combine different ingredients (in our case, AI models) to create a delicious dish (a summary in our case 😋)

OpenAI, on the other hand, is an AI research lab that provides powerful AI models. We use one of their models, GPT-3.5-turbo, to process the lab reports and generate a summary.

The Magic Behind the Scenes

Our tool consists of two parts: a backend script that processes the lab reports and a frontend script that provides a user interface. The backend script reads the text from a PDF file, identifies the key points using OpenAI, and then creates a summary using Langchain. The frontend script provides a user-friendly interface where you can upload your lab report, and displays the key points and the summary of the report.

Building the AI Tool: A Step-by-Step Guide

Now that we’ve set the stage, let’s get our hands dirty and start building this tool.

A. Backend Script

  1. Install the necessary libraries: First, we need to install some libraries. If you’ve ever baked a cake, think of this step as gathering your ingredients. You can install the libraries using pip, which is a package manager for Python.
git clone https://github.com/robinkiplangat/LabScanner.git
cd LabScanner
pip install -r requirements.txt

2. Get your OpenAI API key: To use OpenAI, you need an API key. You can get this key from the OpenAI website after creating an account.

3. Run the backend script: Once you have your ingredients ready, it’s time to start baking! You can run the backend script using Python.

python3 scripts/reports_frontend.py

B. Frontend Script

  1. Install Streamlit: The frontend script is a Streamlit application. Streamlit is a library that allows you to create web applications using Python. You can install it using pip.
  2. Run the frontend script: Once you have installed Streamlit, you can run the frontend script. This will open a new tab in your web browser with the application.
streamlit run scripts/reports_frontend.py

To use the application, upload a lab report, enter your OpenAI API key, and click Submit.

Demo of the App

The application will then display the key points and the summary of the report. All the development code and setup instructions is available on GitHub Here. A demo of the app runs on umzimalabs.streamlit.app

Conclusion

And there you have it! You’ve just built an AI tool that can summarize lab reports. As you can see, building AI tools can be straightforward when you have powerful tools like Langchain and OpenAI. So, the next time you’re faced with a stack of reports, let AI do the heavy lifting!

--

--

Robin Kiplang'at
fourbic

OSINT | Tech | Entrepreneurship | Data Science and Social Research