mirror of
https://github.com/SillyTavern/SillyTavern-Extras.git
synced 2026-03-02 18:10:04 +00:00
Remove hardcoded images list
This commit is contained in:
@@ -2,6 +2,7 @@ const MODULE_NAME = 'expressions';
|
||||
const SETTINGS_KEY = 'extensions_memory_settings';
|
||||
const UPDATE_INTERVAL = 1000;
|
||||
|
||||
let expressionsList = null;
|
||||
let lastCharacter = null;
|
||||
let lastMessage = null;
|
||||
let inApiCall = false;
|
||||
@@ -90,9 +91,9 @@ function removeExpression() {
|
||||
$('.expression_settings').hide();
|
||||
}
|
||||
|
||||
function validateImages() {
|
||||
async function validateImages() {
|
||||
const context = getContext();
|
||||
const IMAGE_LIST = ['joy.png', 'anger.png', 'love.png', 'fear.png', 'surprise.png', 'sadness.png'];
|
||||
const IMAGE_LIST = (await getExpressionsList()).map(x => `${x}.png`);
|
||||
$('.expression_settings').show();
|
||||
$('#image_list').empty();
|
||||
|
||||
@@ -112,6 +113,32 @@ function validateImages() {
|
||||
});
|
||||
}
|
||||
|
||||
async function getExpressionsList() {
|
||||
if (Array.isArray(expressionsList)) {
|
||||
return expressionsList;
|
||||
}
|
||||
|
||||
const url = new URL(getApiUrl());
|
||||
url.pathname = '/api/classify/labels';
|
||||
|
||||
try {
|
||||
const apiResult = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: { 'Bypass-Tunnel-Reminder': 'bypass' },
|
||||
});
|
||||
|
||||
if (apiResult.ok) {
|
||||
const data = await apiResult.json();
|
||||
expressionsList = data.labels;
|
||||
return expressionsList;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function setExpression(character, expression) {
|
||||
const imgUrl = `url('/characters/${character}/${expression}.png')`;
|
||||
$('div.expression').css('background-image', imgUrl);
|
||||
|
||||
@@ -369,6 +369,14 @@ def api_classify():
|
||||
return jsonify({'classification': classification})
|
||||
|
||||
|
||||
@app.route('/api/classify/labels', methods=['GET'])
|
||||
@require_module('classify')
|
||||
def api_classify_labels():
|
||||
classification = classify_text('')
|
||||
labels = [x['label'] for x in classification]
|
||||
return jsonify({'labels': labels})
|
||||
|
||||
|
||||
@app.route('/api/keywords', methods=['POST'])
|
||||
@require_module('keywords')
|
||||
def api_keywords():
|
||||
|
||||
Reference in New Issue
Block a user