-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add on device summary sample (#1263)
* Add on device summary sample * small tweaks and clean up * more clean up * Add link to blog post * show correct error when ai is not supported in browser * addressed comments * fix path
- Loading branch information
1 parent
0a92c15
commit 18a4801
Showing
15 changed files
with
1,749 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
functional-samples/ai.gemini-on-device-summarization/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
16 changes: 16 additions & 0 deletions
16
functional-samples/ai.gemini-on-device-summarization/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# On-device Summarization with Gemini Nano | ||
|
||
This sample demonstrates how to use the experimental Summarization API in Chrome. To learn more about the API and how to sign-up for the preview, head over to [Built-in AI on developer.chrome.com](https://developer.chrome.com/docs/ai/built-in). | ||
|
||
## Overview | ||
|
||
The extension summarizes the content of the currently open tab. It uses Mozilla's [readability](https://github.com/mozilla/readability) library to extract the content of the currently active tab and displays a summary of the page generated by [Chrome's experimental summarization API](https://developer.chrome.com/blog/august2024-summarization-ai) in a side panel. | ||
|
||
## Running this extension | ||
|
||
1. Clone this repository | ||
2. Run `npm install` in this folder to install all dependencies. | ||
3. Run `npm run build` to bundle the content script . | ||
4. Load the 'dist' directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked). | ||
5. Click the extension icon to open the summary side panel. | ||
6. Open any web page, the page's content summary will automatically be displayed in the side panel. |
22 changes: 22 additions & 0 deletions
22
functional-samples/ai.gemini-on-device-summarization/background.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
chrome.sidePanel | ||
.setPanelBehavior({ openPanelOnActionClick: true }) | ||
.catch((error) => console.error(error)); | ||
|
||
chrome.tabs.onActivated.addListener((activeInfo) => { | ||
showSummary(activeInfo.tabId); | ||
}); | ||
chrome.tabs.onUpdated.addListener(async (tabId) => { | ||
showSummary(tabId); | ||
}); | ||
|
||
async function showSummary(tabId) { | ||
const tab = await chrome.tabs.get(tabId); | ||
if (!tab.url.startsWith('http')) { | ||
return; | ||
} | ||
const injection = await chrome.scripting.executeScript({ | ||
target: { tabId }, | ||
files: ['scripts/extract-content.js'] | ||
}); | ||
chrome.storage.session.set({ pageContent: injection[0].result }); | ||
} |
Binary file added
BIN
+3.86 KB
functional-samples/ai.gemini-on-device-summarization/images/icon128.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
BIN
+267 Bytes
functional-samples/ai.gemini-on-device-summarization/images/icon16.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
BIN
+458 Bytes
functional-samples/ai.gemini-on-device-summarization/images/icon32.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
BIN
+890 Bytes
functional-samples/ai.gemini-on-device-summarization/images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
functional-samples/ai.gemini-on-device-summarization/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "Summarizer", | ||
"version": "0.1", | ||
"manifest_version": 3, | ||
"description": "Get a short summary of every webpage.", | ||
"background": { | ||
"service_worker": "background.js" | ||
}, | ||
"permissions": ["tabs", "scripting", "sidePanel", "storage"], | ||
"host_permissions": ["http://*/*", "https://*/*"], | ||
"side_panel": { | ||
"default_path": "sidepanel/index.html" | ||
}, | ||
"action": { | ||
"default_icon": { | ||
"16": "images/icon16.png", | ||
"32": "images/icon32.png", | ||
"48": "images/icon48.png", | ||
"128": "images/icon128.png" | ||
}, | ||
"default_title": "Generate a summary" | ||
} | ||
} |
Oops, something went wrong.