Skip to content

Updated Text-Summarizer-Browser-Plugin Sample #233

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

Closed
wants to merge 9 commits into from
Closed
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
2 changes: 2 additions & 0 deletions Text-Summarizer-Browser-Plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ MANIFEST
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
*.txt

# Unit test / coverage reports
htmlcov/
Expand Down Expand Up @@ -78,6 +79,7 @@ target/
# Jupyter Notebook
.ipynb_checkpoints
**/*.ipynb_checkpoints/
models

# IPython
profile_default/
Expand Down
1 change: 1 addition & 0 deletions Text-Summarizer-Browser-Plugin/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
220 changes: 117 additions & 103 deletions Text-Summarizer-Browser-Plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,127 @@
# Text summarizer browser Plugin Sample

A plug-and-play Chrome extension seamlessly integrates with Flask and leverages an OpenVINO backend for fast and efficient summarization of webpages (via URL) and PDFs (via upload). Powered by LangChain tools, it handles advanced tasks like text splitting and vectorstore management to deliver accurate and meaningful summaries.

## How it Works

A plug-and -play Chrome extension seamlessly integrates with Flask and leverages an OpenVINO backend for fast and efficient summarization of webpages(via URL) and PDFs(via upload). Powered by LangChain tools, it handles advanced tasks like text splitting and vectorstore management to deliver accurate and meaningful summaries.

This Chrome extension acts as the immediate user gateway, offering a minimalist interface right in the browser's toolbar that lets users instantly trigger summarization. It's designed to efficiently capture the required input, whether it's a webpage's URL or content from an uploaded PDF, and securely send this data to the Flask server for further processing.

# Contents
- [Sample Workflow](./Readme.md#sample-workflow)
- [Prerequisites](./Readme.md#prerequisites)
- [Sample Structure](./Readme.md#sample-structure)
- [Run the `Text Summarizer Browser Plugin` Sample](./Readme.md#run-the-text-summarizer-browser-plugin-sample)
- [Setup the environment with uv](./Readme.md#setup-the-environment-with-uv)
- [Load this `Text Summarizer` extension](./Readme.md#load-this-text=summarizer-extension)
- [Contens of `extension` directory](./Readme.md#contents-of-extension-directory)
- [Load an unpacked extension](./Readme.md#load-an-unpacked-extension)
- [Pin the extension](./Readme.md#pin-the-extension)
- [Run the sample](./Readme.md#run-the-sample)
- [Steps to follow via Jupyter Notebook](./Readme.md#steps-to-follow-via-jupyter-notebook)
- [Steps to follow via Terminal](./Readme.md#steps-to-follow-via-terminal)
- [Interact with `Text Summarizer Browser Plugin`](./Readme.md#interact-with-text-summarizer-browser-plugin)


# Sample Workflow

- This architecture is split into two main components: a lightweight **Chrome extension** and a powerful **Flask server**.
- The **Chrome extension** serves as the user's direct interface, enabling them to simply click a button to initiate summarization of the current webpage or to upload a PDF directly from their browser.
- Once activated, it securely sends the webpage URL or the uploaded PDF content to the Flask server.
- This **Flask server**, acting as the intelligent backend, processes the request, orchestrates the summarization using the OpenVINO backend and LangChain tools, and then sends the concise summary back to the extension for display.
- This clear separation of concerns ensures a responsive user experience within the browser while offloading heavy computational tasks to a dedicated and scalable server.

<img width="1000" alt="image" src="./assets/Text-Summarizer-Overview.png">

## Sample Structure

The directory contains:
- **backend:** Includes `code.py` and `server.py` for processing text from webpages or PDFs and managing Flask-related operations.
- **extension:** Contains `manifest.json` for the Chrome extension along with `popup.html`, `popup.js`, and `style.css` for the user interface.

## Prerequisites
## Pre-requisites

| Optimized for | Description |
| :------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| OS | Windows 11 64-bit (22H2, 23H2) and newer or Ubuntu* 22.04 64-bit (with Linux kernel 6.6+) and newer |
| Hardware | Intel® Core™ Ultra Processors |
| Software | 1. [Intel® GPU drivers from Intel® Arc™ & Iris® Xe Graphics for Windows](https://www.intel.com/content/www/us/en/download/785597/intel-arc-iris-xe-graphics-windows.html) or [Linux GPU drivers](https://dgpu-docs.intel.com/driver/client/overview.html) <br> 2. NPU(Optional): [Intel® NPU Driver for Windows](https://www.intel.com/content/www/us/en/download/794734/intel-npu-driver-windows.html) or [Linux NPU Driver](https://github.com/intel/linux-npu-driver/releases) |
| Hardware | 1. [Intel® GPU drivers from Intel® Arc™ & Iris® Xe Graphics for Windows](https://www.intel.com/content/www/us/en/download/785597/intel-arc-iris-xe-graphics-windows.html) or [Linux GPU drivers](https://dgpu-docs.intel.com/driver/client/overview.html) <br> 2. NPU(Optional): [Intel® NPU Driver for Windows](https://www.intel.com/content/www/us/en/download/794734/intel-npu-driver-windows.html) or [Linux NPU Driver](https://github.com/intel/linux-npu-driver/releases) <br> 3. Intel® Core™ Ultra Processors |
| Software | 1. [Intel® GPU drivers from Intel® Arc™ & Iris® Xe Graphics for Windows](https://www.intel.com/content/www/us/en/download/785597/intel-arc-iris-xe-graphics-windows.html), <br> 2. [uv](https://docs.astral.sh/uv/) |
| Browsers | [Google Chrome](https://www.google.com/chrome/dr/download/?brand=MRUS&ds_kid=43700079286123654&gad_source=1&gclid=EAIaIQobChMI0J3fybvSigMV5dXCBB1TDARCEAAYASAAEgL36_D_BwE&gclsrc=aw.ds) & [Microsoft Edge](https://www.microsoft.com/en-us/edge/download?form=MA13FJ)


1. **Install the below necessary tools/packages:**
- Git
- [Git for Windows](https://git-scm.com/downloads)
- Git for Linux
- For Debian/Ubuntu-based systems:
```bash
sudo apt update && sudo apt -y install git
```
- For RHEL/CentOS-based systems:
```bash
sudo dnf update && sudo dnf -y install git
```
- Miniforge
- [Miniforge for Windows](https://conda-forge.org/download/)
- Miniforge for Linux
Download, install the Miniconda using the below commands.
```bash
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh
```
Replace </move/to/miniforge3/bin/folder> with your actual Miniforge bin folder path and run the cd command to go there. Initialize the conda environment and restart the terminal.
```bash
cd </move/to/miniforge3/bin/folder>
```
```bash
./conda init
```

2. **Create a Conda Environment:**
- Run the command:
```bash
conda create -n summarizer_plugin python=3.11 libuv
```
```bash
conda activate summarizer_plugin
```
## Sample Structure

3. **Install Dependencies:**
- Execute:
```bash
pip install -r requirements.txt
```
The directory contains:
- **backend:** Includes `code.py` and `server.py` for processing text from webpages or PDFs and managing Flask-related operations.
- **extension:** Contains `manifest.json` for the Chrome extension along with `popup.html`, `popup.js`, and `style.css` for the user interface. These files are used to load an unapcked extension.
- **`TextSummarizerPlugin.ipynb`:** Notebook which processes text from webpages or PDFs and manages Flask-related operations.


## Run the `Text Summarizer Browser Plugin` Sample:

### Setup Environment with `uv`:
The sample uses [uv](https://docs.astral.sh/uv/) for environment management.
> Steps to install `uv` are as follows. Refer [this documentation](https://docs.astral.sh/uv/getting-started/installation/) this for more information.
> </br> **Windows:** </br>
> ```bash
> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
> ```
>
> </br> **Linux:** </br>
> </br> Use curl to download the script and execute it with sh:
> ```bash
> curl -LsSf https://astral.sh/uv/install.sh | sh
> ```
>
> </br> If your system doesn't have curl, you can use wget:
> ```bash
> wget -qO- https://astral.sh/uv/install.sh | sh
> ```

1. In a terminal, navigate to `Text Summarizer Browser Plugin Sample` folder:
```bash
cd <path/to/folder>
```
2. Sync project dependencies:
```bash
uv sync
```
> **NOTE:** Run the below command if you face any dependency issues:
> ```bash
> uv clean
> ```
### Load this `Text Summarizer` extension

1. **Contents of `extension` directory**
- [`extension` directory](./extension) consists of files, i.e. `manifest.json`, `popup.html`, `popup.js` and `style.css`, used to load an unpacked extension.

2. **Load an unpacked Extension:**
- To load an unpacked extension in developer mode:
- Go to the Extensions page by entering **chrome://extensions** in a new tab. (By design chrome:// URLs are not linkable.)
- Alternatively, **click the Extensions menu puzzle button and select Manage Extensions** at the bottom of the menu.
- Or, click the Chrome menu, hover over More Tools, then select Extensions.
- Enable **Developer Mode** by clicking the toggle switch next to Developer mode.
- Click the **Load unpacked** button and select the `extension directory`.
- Refer to [Chrome’s development documentation](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked) for further details.

4. **Install an ipykernel to select the "summarizer_plugin" environment:**
```bash
python -m ipykernel install --user --name=summarizer_plugin
```
<img width="389" alt="image" src="https://github.com/user-attachments/assets/c276f522-6f03-4aac-91ff-d38faf8c1f67">

>**Note**: Run your terminal as admin to avoid any permission issues.


## Next Steps
3. **Pin the Extension:**

Pin your extension to the toolbar for a quick access to your extension.

<img width="389" alt="image" src="https://github.com/user-attachments/assets/1bcc1571-b2d6-4ece-a3ca-c435733436b5">


### Run the Sample
Below are the steps to run the plugin from Jupyter Notebook **OR** Terminal.

### **Steps to follow via Jupyter Notebook:**
#### **Steps to follow via Jupyter Notebook:**
Once the environment is created, we can run the plugin via [TextSummarizerPlugin.ipynb](./TextSummarizerPlugin.ipynb). Please follow the below steps to open the jupyter notebook:
1. Open Jupyter Notebook & run the cells:
1. Launch Jupyter Notebook:
```
jupyter notebook
uv run jupyter lab
```
2. Select the **summarizer_plugin** kernel.
2. Select the default **ipykernel** kernel.
3. Run all the cells one by one.
4. The last cell at the end of the notebook launches the flask server.
5. Once the flask server is running, open Chrome Browser & click on the pinned text-summarizer

<div class="alert alert-block alert-warning" align="center">OR</div>

### **Steps to follow via Terminal:**
#### **Steps to follow via Terminal:**
1. **Download and Convert the Huggingface Model to OpenVINO IR Format:**
- Log in to Huggingface:
```
Expand All @@ -95,59 +132,36 @@ Once the environment is created, we can run the plugin via [TextSummarizerPlugin
```
mkdir models
cd models
optimum-cli export openvino --model meta-llama/Llama-2-7b-chat-hf --weight-format int4 ov_llama_2
optimum-cli export openvino --model Qwen/Qwen2-7B-Instruct --weight-format int4 ov_qwen7b
uv run optimum-cli export openvino --model meta-llama/Llama-2-7b-chat-hf --weight-format int4 ov_llama_2
uv run optimum-cli export openvino --model Qwen/Qwen2-7B-Instruct --weight-format int4 ov_qwen7b

```
>**Note**: [Raise access request](https://www.llama.com/llama-downloads) for Llama models as it is a gated repository.




2. **Load the Extension:**
- To load an unpacked extension in developer mode:
- Go to the Extensions page by entering **chrome://extensions** in a new tab. (By design chrome:// URLs are not linkable.)
- Alternatively, **click the Extensions menu puzzle button and select Manage Extensions** at the bottom of the menu.
- Or, click the Chrome menu, hover over More Tools, then select Extensions.
- Enable **Developer Mode** by clicking the toggle switch next to Developer mode.
- Click the **Load unpacked** button and select the extension directory.
- Refer to [Chrome’s development documentation](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked) for further details.

<img width="389" alt="image" src="https://github.com/user-attachments/assets/c276f522-6f03-4aac-91ff-d38faf8c1f67">



3. **Pin the Extension:**

Pin your extension to the toolbar to quickly access your extension.

<img width="389" alt="image" src="https://github.com/user-attachments/assets/1bcc1571-b2d6-4ece-a3ca-c435733436b5">




#### Steps to Run the Plugin

1. **Start the Flask Server:**
- Navigate to the backend folder:
2. **Start the Flask Server:**
- In one terminal, navigate to the backend folder:
```
cd ../backend
python server.py
cd ./backend
uv run server.py
```
This step would launch a flask server in browser extension

2. **Open the Chrome Browser:**
- Activate & Pin the loaded extension.
### Interact with `Text Summarizer Browser Plugin`
1. **Open Chrome Extension in Browser:**
- Click on the pinned extension of this text summarizer plugin.
- Plugin UI looks as follows:

<img width="286" alt="image" src="https://github.com/user-attachments/assets/37349acc-ff37-437b-928a-673ca4ad3986">


3. **Select an OpenVINO Model:**
2. **Select an OpenVINO Model:**
- Choose an OpenVINO IR format model previously converted from Huggingface.

<img width="286" alt="image" src="https://github.com/user-attachments/assets/953050c9-c64c-4ce6-831d-626a52547d0b">


4. **Interact with the UI:**
3. **Interact with the UI:**
- Choose either **Web Page** or **PDF** post selecting one of the converted OV models:

<img width="285" alt="image" src="https://github.com/user-attachments/assets/065022e9-c9a2-474c-ae4e-5a2f298a9934">
Expand All @@ -174,5 +188,5 @@ Once the environment is created, we can run the plugin via [TextSummarizerPlugin
<img width="300" alt="image" src="https://github.com/user-attachments/assets/ea05eca2-fa53-4b17-9c85-67a692607376">


5. **Reload the Page:**
4. **Reload the Page:**
- Refresh the webpage or re-open the plugin to restart.
Loading