dashboard and docu updates, added scoring nb
This commit is contained in:
Родитель
fa8071399a
Коммит
62b44c64b4
|
@ -1,6 +1,8 @@
|
|||
'''Module with language and example definition of Verseagility Dashboard'''
|
||||
import os
|
||||
|
||||
def get_languages():
|
||||
'''Define and load languages for dashboard'''
|
||||
LANGUAGES = {
|
||||
"English": "en",
|
||||
"German": "de",
|
||||
|
@ -12,29 +14,34 @@ def get_languages():
|
|||
|
||||
def get_endpoints(LANGUAGES):
|
||||
'''Load endpoints with dictionary of languages from Azure AppSettings'''
|
||||
'''format {"English":"en"}, dict comprehension to read from environment variables'''
|
||||
# Format {"English":"en"}, dict comprehension to read from environment variables
|
||||
# Define URL, full qualified
|
||||
MODEL_ENDPOINTS = {value:os.environ.get(f'ACI_{value.upper()}') for key, value in LANGUAGES.items()}
|
||||
# Define key for respective URL
|
||||
ENDPOINT_KEY = {value:os.environ.get(f'ACI_{value.upper()}_KEY') for key, value in LANGUAGES.items()}
|
||||
return MODEL_ENDPOINTS, ENDPOINT_KEY
|
||||
|
||||
def get_examples():
|
||||
'''Loads example texts'''
|
||||
# For every language defined in get_languages(), bring a default subject
|
||||
DEFAULT_SUBJECT = {
|
||||
'en': "Windows defender shutting everything down",
|
||||
'en': "I am running Windows and it does not work so well any more",
|
||||
'de': "Win 7 ohne Updates",
|
||||
'fr': "Erreur lié à l abonnement",
|
||||
'es': "Error de actualizacion",
|
||||
'it': "Fotocamera schermata nera"
|
||||
}
|
||||
|
||||
# For every language defined in get_languages(), bring a default text belonging to the subject above
|
||||
DEFAULT_TEXT = {
|
||||
'en': "I am running Windows 7 - I thought it couldn't get a virus. Can I have Bill Gates number, need help?! Microsoft should know better...",
|
||||
'en': "Maybe I have a virus? Can you recommend an AntiVirus? I am using Windows Defender. Can I have Bill Gates number, need help?! Microsoft should know better...",
|
||||
'de': "Hallo freunde. Mein Windows 7 Rechner will keine Updates mehr laden - mit folgendem fehlercode 0xa00f4289. Normalerweise funktionieren die Microsoft produkte doch so gut! Kann Bill Gates mir nicht helfen?",
|
||||
'fr': "J'ai renouvelé mon abonnement office et j'obtiens toujous le message d'erreur 'Nous avons rencontré un problème lié à votre abonnement...' J'ai fait tout ce qui est proposé y compris désinstaller et ré-installer et j'obtiens toujours le message d'erreur. Merci de me dire comment régler le tout.",
|
||||
'es': "Cuándo actualizo mi laptop Windows 7 no se actualiza y se queda en 27% y 30% Se reinicia y no la actualiza necesito ayuda.",
|
||||
'it': "Buonasera, se apro la fotocamera, la schermata resta nera e ogni tanto compare il messaggio Non è possibile trovare la fotocamera... codice errore fotocamera 0xa00f4289 Acitve Camera Unplugged. Ho fatto varie verifiche nelle impostazioni del pc (win 10), provato ad aggiornare il driver, disinstallare e riavviare, ho aggiunto la fotocamera nelle eccezioni dell'antivirus... Cosa potrei fare ancora? Grazie!"
|
||||
}
|
||||
|
||||
# Define multiple examples for the languages defined in get_languages()
|
||||
EXAMPLES = {
|
||||
'en': {'Default':
|
||||
{'Subject': DEFAULT_SUBJECT['en'],
|
||||
|
|
|
@ -39,26 +39,32 @@ There are different approaches of possible demo environment setups.
|
|||
|
||||
## Dashboard Customization
|
||||
This section is only required if you follow the _Dashboard - Basic_ or _Dashboard - Premium_ track. If you follow the _Dashboard - Advanced_ track, you can skip it.
|
||||
1. Navigate to the `demo`-subfolder and add your custom logo by replacing the active logo file `logo2_nbg.PNG`. Alternatively, you can change the value in the code and use any other file name in `demo/dashboard.py`.
|
||||
1. Navigate to the `demo`-subfolder and add your custom logo by replacing the active logo file `logo.PNG`. Alternatively, you can change the value in the code and use any other file name in `demo/dashboard.py`.
|
||||
|
||||
2. Change any other structural or text elements in `demo/dashboard.py`.
|
||||
2. Change any other structural or text elements in `demo/dashboard.py`. If you want to go deep into the customization, we recommend you the official documentation platform of [Streamlit](https://docs.streamlit.io/en/stable/api.html). Your ideas and contributions to our demo are highly appreciated!
|
||||
|
||||
3. If you want to go deep into the customization, we recommend you the official documentation platform of [Streamlit](https://www.streamlit.io/). Your ideas and contributions to our demo are highly appreciated!
|
||||
## Set Languages and Endpoint Keys
|
||||
This section is only required if you follow the _Dashboard - Advanced_ or _Dashboard - Premium_ track. For an end-to-end custom solution based on your own data, first follow the instructions which you find on this part of the documentation: [Verseagility Setup](../setup).
|
||||
|
||||
## Set the Endpoint Keys
|
||||
This section is only required if you follow the _Dashboard - Advanced_ or _Dashboard - Premium_ track. For an end-to-end custom solution based on your own data, first follow the instructions which you find on this page: [Verseagility Setup](../Verseagility-Setup.md).
|
||||
Next, open the script `demo/load_examples.py` and adjust the following parts as needed (depending on whether you build a multi-language demo):
|
||||
- `get_languages()`
|
||||
- dictionary of languages in the structure of `"language": "language-code"`, e.g. `"German": "de"`
|
||||
- `get_endpoints()`
|
||||
- load endpoints from App Settings
|
||||
- ```python
|
||||
MODEL_ENDPOINTS = {
|
||||
'en': 'http://[YOUR URL GOES HERE].azurecontainer.io/score'
|
||||
}
|
||||
|
||||
Once these are completed, [take the endpoints with the respective keys](../Verseagility-Setup/Deploy-Service.md) and substitute the existing ones in `demo/dashboard.py`.
|
||||
ENDPOINT_KEY = {
|
||||
'en': '[YOUR ENDPOINT KEY GOES HERE]'
|
||||
}
|
||||
```
|
||||
- `get_examples()`
|
||||
- definition of a few examples as needed, consisting of `DEFAULT_SUBJECT`, `DEFAULT_TEXT`
|
||||
Once these are completed, [take the endpoints with the respective keys](../setup/06%20-%20Deployment.md)
|
||||
|
||||
```python
|
||||
MODEL_ENDPOINTS = {
|
||||
'en': 'http://[YOUR URL GOES HERE].azurecontainer.io/score'
|
||||
}
|
||||
|
||||
ENDPOINT_KEY = {
|
||||
'en': '[YOUR ENDPOINT KEY GOES HERE]'
|
||||
}
|
||||
```
|
||||
|
||||
Save your changes and continue with the next section of this page for dashboard deployment.
|
||||
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"# Verseagility Endpoint Request"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"source": [
|
||||
"import json\r\n",
|
||||
"import requests\r\n",
|
||||
"import configparser"
|
||||
],
|
||||
"outputs": [],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"source": [
|
||||
"# Get config file\r\n",
|
||||
"config = configparser.ConfigParser()\r\n",
|
||||
"config.read('../config.ini')\r\n",
|
||||
"endpoint = config['API']['endpoint']\r\n",
|
||||
"region = config['API']['region']\r\n",
|
||||
"key = config['API']['key']"
|
||||
],
|
||||
"outputs": [],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"source": [
|
||||
"def score_model(text, endpoint=endpoint, region=region, key=key):\r\n",
|
||||
" # URL for the web service\r\n",
|
||||
" scoring_uri = f'http://{endpoint}.{region}.azurecontainer.io/score'\r\n",
|
||||
" # Set the content type\r\n",
|
||||
" headers = {'Content-Type': 'application/json'}\r\n",
|
||||
" # If authentication is enabled, set the authorization header\r\n",
|
||||
" headers['Authorization'] = f'Bearer {key}'\r\n",
|
||||
" scores = []\r\n",
|
||||
" # Iterate\r\n",
|
||||
" data = [{\r\n",
|
||||
" \"subject\": \"\",\r\n",
|
||||
" \"body\": text.replace(\"'\", \"\").replace('\"', '')\r\n",
|
||||
" }]\r\n",
|
||||
" # Convert to JSON string\r\n",
|
||||
" input_data = json.dumps(data)\r\n",
|
||||
" # Make the request and display the response\r\n",
|
||||
" resp = requests.post(scoring_uri, input_data, headers=headers)\r\n",
|
||||
" try:\r\n",
|
||||
" pred = json.loads(resp.text)[0]['result'][0]['category']\r\n",
|
||||
" except:\r\n",
|
||||
" pred = \"None\"\r\n",
|
||||
" return pred"
|
||||
],
|
||||
"outputs": [],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"source": [
|
||||
"score_model('windows is such a great product and i love using it, who does agree with me?')"
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "execute_result",
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'Windows'"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"execution_count": 25
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"source": [],
|
||||
"outputs": [],
|
||||
"metadata": {}
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"orig_nbformat": 4,
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.7.9",
|
||||
"mimetype": "text/x-python",
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"pygments_lexer": "ipython3",
|
||||
"nbconvert_exporter": "python",
|
||||
"file_extension": ".py"
|
||||
},
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3.7.9 64-bit ('.venv': venv)"
|
||||
},
|
||||
"interpreter": {
|
||||
"hash": "8f6a11dde7052ac1dd90d2a6ad2b6809c8f3f725167bd8fcdc8934151368885b"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
Загрузка…
Ссылка в новой задаче