-
-
Save sureshkumargondi/31bf06bb43ac1097348ce9698c4df3cb to your computer and use it in GitHub Desktop.
Question generation chrome extension
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
""" Chrome Manifest file: https://developer.chrome.com/docs/extensions/mv3/getstarted/ | |
{ | |
"manifest_version": 3, | |
"name": "Hugging Face Question Generator", | |
"version": "1.0", | |
"description": "Generate questions based on selected text", | |
"permissions": [ | |
"contextMenus", | |
"storage", | |
"tabs", | |
"activeTab", | |
"scripting" | |
], | |
"background": { | |
"service_worker": "generate_question.js" | |
}, | |
"icons":{ | |
"128": "icon.png" | |
} | |
} | |
""" | |
generateQuestion = function(info, tab){ | |
const path = "https://api-inference.huggingface.co/models/voidful/bart-eqg-question-generator"; | |
const payload = JSON.stringify({ | |
"inputs": info.selectionText | |
}); | |
const options = { | |
"wait_for_model": true, | |
"use_gpu": false, | |
"method" : "POST", | |
"contentType" : "application/json", | |
"payload" : payload, | |
"headers" = {"Authorization": "Bearer YOUR_TOKEN"}, | |
}; | |
(async () => { | |
const rawResponse = await fetch(path, { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
}, | |
options: { | |
use_gpu: false, | |
wait_for_model: true, | |
}, | |
body: payload | |
}); | |
const content = await rawResponse.json(); | |
console.log(content[0]["generated_text"]); | |
})(); | |
}; | |
chrome.contextMenus.create({ | |
title: "Generate Question with HF", | |
id: "Generate Question with HF 4", | |
contexts:["selection"], // ContextType | |
}) | |
chrome.contextMenus.onClicked.addListener(generateQuestion); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment