A Colab-based Streamlit application that extracts graph data (entities and relationships) from text input using LangChain and OpenAI's GPT-4o models, then visualizes it interactively as a dynamic knowledge graph.
- π Input support for both
.txtuploads and direct text entry - π§ Automatic entity and relationship extraction using GPT-4o
- πΈοΈ Interactive knowledge graph with physics-based layout
- π Real-time drag, zoom, and hover interactivity with PyVis
- π Fully deployable via Streamlit within Colab using
%%writefile
- Python 3.8+
- OpenAI API key
The following Python packages are required:
langchain >= 0.1.0langchain-experimental >= 0.0.45langchain-openai >= 0.1.0python-dotenv >= 1.0.0pyvis >= 0.3.2streamlit >= 1.32.0
Install all dependencies using:
pip install -r requirements.txtIn Colab, you can also run:
!pip install -r requirements.txtCreate a .env file in the notebook with:
%%writefile .env
OPENAI_API_KEY=your_openai_api_key_hereOr set it dynamically in the notebook:
import os
os.environ["OPENAI_API_KEY"] = "your_openai_api_key_here"Since this app uses %%writefile to generate scripts:
- Run each notebook cell to write required files like
app.py - Launch the Streamlit app using:
!streamlit run app.pyColab will give you a public URL to access the interface.
-
Select input method in the sidebar:
- π Upload a
.txtfile, or - π Enter text directly
- π Upload a
-
Click "Generate Knowledge Graph"
-
Interact with the graph:
- Drag nodes
- Zoom in/out with mouse wheel
- Hover to see details
- Apply graph filters and layouts
- Your input text is sent through a LangChain
GraphTransformer - GPT-4o identifies
(entity) - [relationship] β (entity)triplets - A NetworkX graph is built from those triplets
- PyVis visualizes the graph inside Streamlit
Example triplets:
(Isaac Newton) - [discovered] β (Laws of Motion)
(Laws of Motion) - [published in] β (1687)
All scripts are generated via Colab using %%writefile:
βββ KnowledgeGraph.ipynb # Main notebook
βββ app.py # Streamlit app
βββ utils.py # Helper logic (if needed) (not in the project yet)
βββ .env # API key
βββ requirements.txt # Dependencies
Β© Aditya Saxena, 2025 Licensed under the MIT License. See: MIT License

