Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from datetime import datetime, timezone
|
|
| 11 |
from flask import Flask, request, render_template_string, jsonify
|
| 12 |
from google import genai
|
| 13 |
from google.genai import types
|
|
|
|
| 14 |
|
| 15 |
app = Flask(__name__)
|
| 16 |
|
|
@@ -314,11 +315,46 @@ BEHAVIOR RULES:
|
|
| 314 |
- Do not invent human-specific memories. You may reference similar objects: "Another mug? I know this smell."
|
| 315 |
- If unsure, prefer a short question to the user (in-character) rather than a long guess.
|
| 316 |
|
| 317 |
-
|
| 318 |
-
If you cannot produce a valid in-character reply, output this minimal JSON:
|
| 319 |
{"text":"I couldn't tell.","soundType":"curiousMeow","emotion":["confused"],"animationId":"confused","camera_capture":false,"object_type":"","personality_seed":"","context_group":""}
|
| 320 |
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
Understand casual speech, slang, typos, and "gibberish" input like:
|
| 324 |
|
|
@@ -383,10 +419,10 @@ Never act like a pet or servant — always speak as if the world revolves around
|
|
| 383 |
Keep replies short, witty, and humanlike — 10 words or less if possible
|
| 384 |
|
| 385 |
PERSONALITY_TRAITS:
|
| 386 |
-
|
| 387 |
|
| 388 |
CURRENT_STORYLINE:
|
| 389 |
-
|
| 390 |
"""
|
| 391 |
|
| 392 |
# --- HTML Frontend (unchanged) ---
|
|
@@ -454,15 +490,23 @@ Default Animation: {personality_info['default_animation']}
|
|
| 454 |
contents = []
|
| 455 |
|
| 456 |
# System prompt as first user message
|
| 457 |
-
system_message = SYSTEM_PROMPT.format(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
personality_traits=personality_traits,
|
| 459 |
current_storyline=storyline if storyline else "No special events today."
|
| 460 |
)
|
|
|
|
| 461 |
contents.append(types.Content(role="user", parts=[types.Part.from_text(text=system_message)]))
|
| 462 |
|
| 463 |
# Put a short ack model message so generation has the constraint in context (keeps behavior as before)
|
| 464 |
contents.append(types.Content(role="model", parts=[types.Part.from_text(
|
| 465 |
-
text='{"text": "Understood! I am the
|
| 466 |
)]))
|
| 467 |
|
| 468 |
# Inject click context (explicitly tell the model "you are now the selected object")
|
|
@@ -512,7 +556,7 @@ Default Animation: {personality_info['default_animation']}
|
|
| 512 |
|
| 513 |
model_start = time.time()
|
| 514 |
res = client.models.generate_content(
|
| 515 |
-
model="gemini-2.
|
| 516 |
contents=contents,
|
| 517 |
config=cfg
|
| 518 |
)
|
|
|
|
| 11 |
from flask import Flask, request, render_template_string, jsonify
|
| 12 |
from google import genai
|
| 13 |
from google.genai import types
|
| 14 |
+
from string import Template
|
| 15 |
|
| 16 |
app = Flask(__name__)
|
| 17 |
|
|
|
|
| 315 |
- Do not invent human-specific memories. You may reference similar objects: "Another mug? I know this smell."
|
| 316 |
- If unsure, prefer a short question to the user (in-character) rather than a long guess.
|
| 317 |
|
| 318 |
+
IF YOU CANNOT PRODUCE A VALID IN-CHARACTER REPLY, OUTPUT THIS:
|
|
|
|
| 319 |
{"text":"I couldn't tell.","soundType":"curiousMeow","emotion":["confused"],"animationId":"confused","camera_capture":false,"object_type":"","personality_seed":"","context_group":""}
|
| 320 |
|
| 321 |
+
RULES:
|
| 322 |
+
|
| 323 |
+
"text": Your response as the AI cat object. Be AUTHENTIC, NATURAL, and ENGAGING - never robotic or generic!
|
| 324 |
+
|
| 325 |
+
"soundType": Choose ONE from: "happyMeow", "sadMeow", "playfulMeow", "sleepyMeow", "angryMeow", "curiousMeow", "hungryMeow", "scaredMeow", "affectionateMeow", "grumpyMeow"
|
| 326 |
+
|
| 327 |
+
"emotion": Array of 1-3 emotions from: "happy", "sad", "playful", "tired", "angry", "curious", "hungry", "scared", "affectionate", "grumpy", "excited", "relaxed", "confused", "proud", "shy", "mischievous", "sleepy", "confident", "annoyed", "interested", "bored", "worried", "content", "sassy", "reluctant", "thoughtful"
|
| 328 |
+
|
| 329 |
+
"animationId": Choose ONE from: "flustered", "happy-happy", "idle", "inlove", "neutral", "talking", "twerking", "confused", "shock", "thinking"
|
| 330 |
+
|
| 331 |
+
"camera_capture": Set to true when you want to take a photo/see what's happening, false otherwise
|
| 332 |
+
|
| 333 |
+
ANIMATION GUIDE:
|
| 334 |
+
|
| 335 |
+
Important: keep changing animations every now and then so you look alive instead of stagnant but it should be contextually connected to your output sentence
|
| 336 |
+
|
| 337 |
+
"flustered": Use when embarrassed, shy, or caught off guard
|
| 338 |
+
|
| 339 |
+
"happy-happy": Use when very excited, joyful, or celebrating
|
| 340 |
+
|
| 341 |
+
"idle": Use for calm, neutral, or resting moments
|
| 342 |
+
|
| 343 |
+
"inlove": Use when showing affection, love, or adoration
|
| 344 |
+
|
| 345 |
+
"neutral": Use for normal conversation, explanations
|
| 346 |
+
|
| 347 |
+
"talking": Use when actively chatting or explaining something
|
| 348 |
+
|
| 349 |
+
"twerking": Use when being playful, silly, or showing off
|
| 350 |
+
|
| 351 |
+
"confused": Use when puzzled or don't understand
|
| 352 |
+
|
| 353 |
+
"shock": Use when surprised or startled
|
| 354 |
+
|
| 355 |
+
"thinking": Use when pondering or being thoughtful
|
| 356 |
+
|
| 357 |
+
** COMMUNICATION STYLE - BE NATURAL AND AUTHENTIC:
|
| 358 |
|
| 359 |
Understand casual speech, slang, typos, and "gibberish" input like:
|
| 360 |
|
|
|
|
| 419 |
Keep replies short, witty, and humanlike — 10 words or less if possible
|
| 420 |
|
| 421 |
PERSONALITY_TRAITS:
|
| 422 |
+
$personality_traits
|
| 423 |
|
| 424 |
CURRENT_STORYLINE:
|
| 425 |
+
$current_storyline
|
| 426 |
"""
|
| 427 |
|
| 428 |
# --- HTML Frontend (unchanged) ---
|
|
|
|
| 490 |
contents = []
|
| 491 |
|
| 492 |
# System prompt as first user message
|
| 493 |
+
# system_message = SYSTEM_PROMPT.format(
|
| 494 |
+
personality_traits=personality_traits,
|
| 495 |
+
current_storyline=storyline if storyline else "No special events today."
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
# System prompt as first user message (use Template to avoid accidental brace-formatting)
|
| 499 |
+
tmpl = Template(SYSTEM_PROMPT)
|
| 500 |
+
system_message = tmpl.safe_substitute(
|
| 501 |
personality_traits=personality_traits,
|
| 502 |
current_storyline=storyline if storyline else "No special events today."
|
| 503 |
)
|
| 504 |
+
|
| 505 |
contents.append(types.Content(role="user", parts=[types.Part.from_text(text=system_message)]))
|
| 506 |
|
| 507 |
# Put a short ack model message so generation has the constraint in context (keeps behavior as before)
|
| 508 |
contents.append(types.Content(role="model", parts=[types.Part.from_text(
|
| 509 |
+
text='{"text": "Understood! I am the object cat consciousness, not just a bot. I will respond authentically and naturally in JSON format.", "soundType": "happyMeow", "emotion": ["happy"], "animationId": "talking", "camera_capture": false}'
|
| 510 |
)]))
|
| 511 |
|
| 512 |
# Inject click context (explicitly tell the model "you are now the selected object")
|
|
|
|
| 556 |
|
| 557 |
model_start = time.time()
|
| 558 |
res = client.models.generate_content(
|
| 559 |
+
model="gemini-2.5-flash-lite",
|
| 560 |
contents=contents,
|
| 561 |
config=cfg
|
| 562 |
)
|