Embedded Supervision Widget (Beta)
Embedded Supervision Widget (Beta)
Updated on May 5, 2026
Published on Sep 16, 2024
5 minute(s) read
The Supervision widget enables you to embed our Supervision & QA tasks within a third-party workflow system. Thus, you no longer have to switch between Hyperscience and your existing workflow system to complete tasks.
Supported Tasks
Our Supervision widget supports the following types of tasks:
- Supervision:
- Document Classification
- Identification
- Transcription
- Flexible Extraction
- Custom Supervision
- QA:
- Document Classification
- Identification
- Transcription
Not supported for SaaS instances
The Supervision widget is available only for on-premise / private cloud instances of Hyperscience.
Note that the Supervision widget feature is in beta and is subject to change in future releases. If you’d like to embed a Supervision widget into your third-party system, contact your Hyperscience representative for more information.
Embedding a Supervision widget
You can embed a Supervision widget by following the below steps:
Get access to a Hyperscience instance.
- To embed the Supervision widget into a third-party system, you need to get access to a Hyperscience instance installed on version 32+.
Create a method for accessing our API tokens.
Users are authenticated in the widget using their API token. To get the API token, we recommend querying the /profile/user//token endpoint on your server. You can then forward the obtained API token to the frontend that implements the widget.
Step 2a: Set the ALLOWED_ORIGINS variable
Ask your system admin to do the following, and then restart and reinitialize the Hyperscience application:
ALLOWED_ORIGINS=https://example.com
Step 2b: Create a superuser
To access the API token endpoint, you have to create a superuser. To create a superuser:
- Run the following command.
docker exec -it /var/www/venv/bin/python /var/www/forms/forms/manage.py createsuperuser
- Follow the on-screen instructions.
- Open the Hyperscience application.
- Go to Users > Users.
- Click on the superuser’s username.
- Copy the superuser’s authentication token.
We recommend adding the superuser’s username to the TOKEN_REVALIDATION_EXEMPTED_USERS variable in the “.env” file to avoid unexpected changes to the API token.
Step 2c : Create a new endpoint to return the current user’s API token, if necessary
Depending on whether your server sends user data to your third-party system, you may need to create an endpoint that returns the user's token.
| If... | Then... | | Your server sends user data to your third-party system. | You can add the users’ API tokens to the relevant entity in the third-party system. | | Your server does not send user data to your third-party system. | You need to create a new endpoint that returns the user’s API token. |
Here is an example of how to create a new endpoint in the backend that returns the user’s API token:
@app.route('/hyperscience/user-token', methods=['GET'])
def get_user_api_token():
username = request.user.username
username = quote(username, safe='~()*!.
res = requests.get(
f'https:///profile/user/{username}/token',
headers = { 'Authorization': f'Bearer {SUPERUSER_API_TOKEN}'}
)
return res.text
- Import the Supervision widget into your third-party system.
Import the widget’s JavaScript and CSS to the frontend:
Add a container for the widget. You must set the container’s position property to relative:<link rel="stylesheet" href="https://<HS Instance>/static/widget/main.css"> <script src="https://<HS Instance>/static/widget/main.js" type="text/javascript"></script>
Initialize the widget in JavaScript:<div id="hs-1" style="position:relative;"></div><script type="text/javascript"> fetch('https://<Server>/hyperscience/user-token') .then(res => res.text()) .then((apiToken) => { HyperscienceWidget.init('hs-1', { url: 'https://<HS Instance>', api_token: apiToken, <widget_options> }); }); </script>
Note the following about the widget:
- The widget’s min-width property is 1000px.
- The widget’s min-height property is 700px.
- Configure the widget.
After importing the widget, window.HyperscienceWidget will become available. The following functions are available:
- Purpose
- MessageType
- init
- destroy
Purpose
Purpose is an enum of task purposes.
enum Purpose {
DOCUMENT_CLASSIFICATION = 'document_classification',
IDENTIFICATION = 'identification',
TRANSCRIPTION = 'transcription',
FLEXIBLE_EXTRACTION = 'flexible_extraction',
CUSTOM_SUPERVISION = 'custom_supervision',
DOCUMENT_CLASSIFICATION_QA = 'document_classification_qa',
IDENTIFICATION_QA = 'identification_qa',
TRANSCRIPTION_QA = 'transcription_qa',
}
MessageType
MessageType is an enum of message types for the callback function.
enum MessageType {
ERROR = 'error',
COMPLETE = 'complete',
}
init(id, options)
init is a function that initializes the widget to an HTML element. The parameters of the init function are the following:
- Element ID: string
- Options: object
- url: string (URL of the Hyperscience instance)
- api_token: string (User’s API Token)
- callback: function (optional) for handling success and errors)
- The callback is called for errors and completed tasks.
- Options: object
Example of the init function:
<script type="text/javascript">
const hyperscienceCallback = (message_type, info) => {
if (message_type === HyperscienceWidget.MessageType.ERROR) {
console.error(info.message);
} else if (message_type === HyperscienceWidget.MessageType.COMPLETE) {
console.log('Tasks Completed', info);
HyperscienceWidget.destroy('hs-1');
}
};
HyperscienceWidget.init('hs-1', {
url: 'https://<HS Instance>',
api_token: '12345678910',
submission_id: 10,
callback: hyperscienceCallback,
});
</script>
destroy(id)
destroy is a function that destroys the widget in an HTML element. The parameters of the destroy function are the following:
- HTML element ID
Example of the destroy function:
<script type="text/javascript">
HyperscienceWidget.destroy('hs-1');
</script>
Additional notes
- Upon first login, the system automatically creates and assigns an API token to the user who is logging in. To be able to log in through the Supervision widget, a user needs to have logged in at least once to the main Hyperscience application. All subsequent logins can happen through the widget, using the user’s API token.