Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bookmind app #133

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions examples/bookmind_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# BookMind

[![thumbnail](https://github.com/user-attachments/assets/11c6f1f3-59db-4638-9b1a-68f1d25efec4)](https://youtu.be/DL4-DswxfEM)

BookMind is a web application that allows users to explore character relationships and storylines in books using AI-powered visualizations. The application provides interactive mind maps, AI chatbots for deep questions, book summaries, and community contributions.

## Features

- Interactive Mind Maps: Visualize relationships between characters and plot elements.
- AI Chatbot: Ask deep questions about the book and get insightful answers.
- Book Summaries: Get concise overviews of plots and themes.
- Community Contributions: Add and refine maps with fellow book lovers.

## Prerequisites

- Node.js
- Python >= 3.10
- LlamaStack server running locally
- Environment variables:
- LLAMA_STACK_PORT
- INFERENCE_MODEL
- REACT_APP_GOOGLE_BOOKS_API_KEY

## Getting Started

### Run llama-stack

1. Setting up Ollama server
Please check the [Ollama Documentation](https://github.com/ollama/ollama) on how to install and run Ollama. After installing Ollama, you need to run `ollama serve` to start the server.

```
export INFERENCE_MODEL="meta-llama/Llama-3.2-3B-Instruct"

# ollama names this model differently, and we must use the ollama name when loading the model
export OLLAMA_INFERENCE_MODEL="llama3.2:3b-instruct-fp16"
ollama run $OLLAMA_INFERENCE_MODEL --keepalive 60m
```

2. Running `llama-stack` server

```
pip install llama-stack

export LLAMA_STACK_PORT=5000

# This builds llamastack-ollama conda environment
llama stack build --template ollama --image-type conda

conda activate llamastack-ollama

llama stack run \
--port $LLAMA_STACK_PORT \
--env INFERENCE_MODEL=$INFERENCE_MODEL \
--env OLLAMA_URL=http://localhost:11434 \
ollama
```

### Backend Setup

1. Install dependencies:

```
cd server
pip install -r requirements.txt
```

2. Set `.env` in the `server` directory

You should modify the name of `example.env` to `.env` in the `server` directory.
**Modify INFERENCE_MODEL in example.env with yours.**

3. Run the server:

```
python server.py
```

### Frontend Setup

1. Set up GOOGLE_BOOKS_API_KEY:

You should rename `example.env` with `.env` and replace `{YOUR_API_KEY}` with your [google_books_api_key](https://developers.google.com/books/docs/v1/using) after getting your api key.

```
REACT_APP_GOOGLE_BOOKS_API_KEY={YOUR_API_KEY}
```

2. Install dependencies and run the application:

```
npm install
npm start
```

## Usage

1. Initialize Memory: Upload your book or choose from the library to initialize memory.
2. AI Analysis: The AI analyzes the book and generates a mind map.
3. Explore Insights: Explore relationships, themes, and Q&A insights.

## What did we use Llama-stack in BookMind?

1️⃣ Llama Inference models: You can start a LLM application using various LLM services easily.
2️⃣ RAG with FAISS: We leveraged FAISS in Llama-stack for Retrieval-Augmented Generation, enabling real-time responses to character relationship questions.
3️⃣ Multi-Hop Reasoning: Our system performs sequential inference—first extracting characters and relationships, then generating graphized mind map data in JSON for visual storytelling.

## Contributors

[Original Repo](https://github.com/seyeong-han/BookMind)
[seyeong-han](https://github.com/seyeong-han)
[sunjinj](https://github.com/SunjinJ)
[WonHaLee](https://github.com/WonHaLee)
1 change: 1 addition & 0 deletions examples/bookmind_app/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_GOOGLE_BOOKS_API_KEY={YOUR_API_KEY}
48 changes: 48 additions & 0 deletions examples/bookmind_app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "bookmind",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.7.7",
"fs": "^0.0.1-security",
"lottie-react": "^2.4.0",
"lucide-react": "^0.460.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-force-graph": "^1.44.7",
"react-force-graph-2d": "^1.25.8",
"react-router-dom": "^7.0.1",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"tailwindcss": "^3.4.15"
}
}
Binary file added examples/bookmind_app/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions examples/bookmind_app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added examples/bookmind_app/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/bookmind_app/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions examples/bookmind_app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions examples/bookmind_app/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
27 changes: 27 additions & 0 deletions examples/bookmind_app/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Book Character Graph API

A Flask-based API server that analyzes books to create character relationship graphs and provides an interactive query interface using LlamaStack.

## Features

- Character and relationship extraction from books
- Graph generation of character relationships
- Memory-based query system for book details
- Interactive Q&A about book characters and plots

## Prerequisites

- Python 3.x
- LlamaStack server running locally
- Environment variables:
- `LLAMA_STACK_PORT`
- `INFERENCE_MODEL`

## Get Started

```bash
# Install dependencies
pip install -r requirements.txt

python server.py
```
3 changes: 3 additions & 0 deletions examples/bookmind_app/server/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LLAMA_STACK_PORT=5000
INFERENCE_MODEL="meta-llama/Llama-3.2-3B-Instruct"
SERVER_PORT=5001
5 changes: 5 additions & 0 deletions examples/bookmind_app/server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flask
flask-cors
llama_stack_client
asyncio
werkzeug
Loading