mirror of
https://github.com/SillyTavern/SillyTavern-Extras.git
synced 2026-04-24 00:18:58 +00:00
add support for "/emote xxx" in talkinghead
This commit is contained in:
@@ -688,6 +688,15 @@ def start_talking():
|
||||
def stop_talking():
|
||||
return talkinghead.stop_talking()
|
||||
|
||||
@app.route('/api/talkinghead/set_emotion', methods=["POST"])
|
||||
@require_module("talkinghead")
|
||||
def emote():
|
||||
data = request.get_json()
|
||||
if "emotion_name" not in data or not isinstance(data["emotion_name"], str):
|
||||
abort(400, '"emotion_name" is required')
|
||||
emotion_name = data["emotion_name"]
|
||||
return talkinghead.setEmotion([{"label": emotion_name, "score": 1.0}]) # mimic the `classify` API result
|
||||
|
||||
@app.route('/api/talkinghead/result_feed')
|
||||
@require_module("talkinghead")
|
||||
def result_feed():
|
||||
|
||||
@@ -66,6 +66,9 @@ def setEmotion(_emotion: Dict[str, float]) -> None:
|
||||
|
||||
Currently, we pick the emotion with the highest confidence score.
|
||||
|
||||
The `set_emotion` API endpoint also uses this function to set the current emotion,
|
||||
with a manually formatted dictionary containing just one entry.
|
||||
|
||||
_emotion: result of sentiment analysis: {emotion0: confidence0, ...}
|
||||
"""
|
||||
global current_emotion
|
||||
@@ -78,8 +81,16 @@ def setEmotion(_emotion: Dict[str, float]) -> None:
|
||||
highest_score = item["score"]
|
||||
highest_label = item["label"]
|
||||
|
||||
logger.debug(f"setEmotion: applying emotion {highest_label}")
|
||||
# Never triggered currently, because `setSpriteSlashCommand` at the client end (`SillyTavern/public/scripts/extensions/expressions/index.js`)
|
||||
# searches for a static sprite for the given expression, and does not proceed to `sendExpressionCall` if not found.
|
||||
# So beside `talkinghead.png`, your character also needs the static sprites for "/emote xxx" to work.
|
||||
if highest_label not in global_animator_instance.emotions:
|
||||
logger.warning(f"setEmotion: emotion '{highest_label}' does not exist, setting to 'neutral'")
|
||||
highest_label = "neutral"
|
||||
|
||||
logger.info(f"setEmotion: applying emotion {highest_label}")
|
||||
current_emotion = highest_label
|
||||
return f"emotion set to {highest_label}"
|
||||
|
||||
def unload() -> str:
|
||||
"""Stop animation."""
|
||||
|
||||
Reference in New Issue
Block a user