Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -471,8 +471,8 @@ if ON_HF:
|
|
| 471 |
)
|
| 472 |
_hf_model.eval()
|
| 473 |
|
| 474 |
-
@spaces.GPU(duration=
|
| 475 |
-
def _hf_gpu_generate(messages, max_new_tokens=
|
| 476 |
model = _hf_model.to("cuda")
|
| 477 |
try:
|
| 478 |
# Ask the model not to emit chain-of-thought, if it supports it
|
|
@@ -779,7 +779,7 @@ class Joe:
|
|
| 779 |
self.running = False
|
| 780 |
self.history = deque(maxlen=30)
|
| 781 |
self.current_data = {}
|
| 782 |
-
self.current_message = ("Joe", "
|
| 783 |
self.current_ascii = ""
|
| 784 |
self.current_context = ""
|
| 785 |
self.current_thinking = ""
|
|
@@ -1243,12 +1243,19 @@ How do I feel right now?"""
|
|
| 1243 |
frags = re.split(r"[.!?\n|]+", text)
|
| 1244 |
lines = [f.strip() for f in frags if len(f.strip()) > 2][:6]
|
| 1245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1246 |
if lines:
|
| 1247 |
# Deduplicate and clean
|
| 1248 |
seen = set()
|
| 1249 |
clean = []
|
| 1250 |
for l in lines:
|
| 1251 |
-
l = l.strip().strip('.')
|
| 1252 |
if l and l.lower() not in seen and len(l) > 2:
|
| 1253 |
seen.add(l.lower())
|
| 1254 |
clean.append(l)
|
|
@@ -1449,7 +1456,7 @@ How do I feel right now?"""
|
|
| 1449 |
data.get("minute", 0) // 5, # Refresh every 5 min
|
| 1450 |
data.get("user_pattern", ""),
|
| 1451 |
data.get("audio", {}).get("type", ""),
|
| 1452 |
-
int(time.time()) //
|
| 1453 |
]
|
| 1454 |
return hashlib.md5(str(key_parts).encode()).hexdigest()[:8]
|
| 1455 |
|
|
@@ -1545,7 +1552,10 @@ def connect():
|
|
| 1545 |
|
| 1546 |
def start():
|
| 1547 |
agent.running = True
|
| 1548 |
-
|
|
|
|
|
|
|
|
|
|
| 1549 |
return f"Agent started ({LLM_MODE})"
|
| 1550 |
|
| 1551 |
def stop():
|
|
@@ -1626,7 +1636,10 @@ def hf_step():
|
|
| 1626 |
"""One agent iteration driven by the Gradio Timer. On HF Spaces the LLM
|
| 1627 |
must be called from a request context (not a background thread) so ZeroGPU
|
| 1628 |
can allocate a GPU — that's what this provides. Returns dashboard outputs."""
|
| 1629 |
-
|
|
|
|
|
|
|
|
|
|
| 1630 |
try:
|
| 1631 |
data = agent.collect_data()
|
| 1632 |
data["audio"] = agent.audio.get_context()
|
|
|
|
| 471 |
)
|
| 472 |
_hf_model.eval()
|
| 473 |
|
| 474 |
+
@spaces.GPU(duration=25)
|
| 475 |
+
def _hf_gpu_generate(messages, max_new_tokens=96):
|
| 476 |
model = _hf_model.to("cuda")
|
| 477 |
try:
|
| 478 |
# Ask the model not to emit chain-of-thought, if it supports it
|
|
|
|
| 779 |
self.running = False
|
| 780 |
self.history = deque(maxlen=30)
|
| 781 |
self.current_data = {}
|
| 782 |
+
self.current_message = ("Hi, I am Joe", "Press Start", "to wake me up", "")
|
| 783 |
self.current_ascii = ""
|
| 784 |
self.current_context = ""
|
| 785 |
self.current_thinking = ""
|
|
|
|
| 1243 |
frags = re.split(r"[.!?\n|]+", text)
|
| 1244 |
lines = [f.strip() for f in frags if len(f.strip()) > 2][:6]
|
| 1245 |
|
| 1246 |
+
# Normalize to a flat list of strings (model JSON can be messy:
|
| 1247 |
+
# bools, ints, nested values, or a bare string instead of a list).
|
| 1248 |
+
if isinstance(lines, (str, bytes)):
|
| 1249 |
+
lines = [lines]
|
| 1250 |
+
elif not isinstance(lines, list):
|
| 1251 |
+
lines = []
|
| 1252 |
+
|
| 1253 |
if lines:
|
| 1254 |
# Deduplicate and clean
|
| 1255 |
seen = set()
|
| 1256 |
clean = []
|
| 1257 |
for l in lines:
|
| 1258 |
+
l = str(l).strip().strip('.')
|
| 1259 |
if l and l.lower() not in seen and len(l) > 2:
|
| 1260 |
seen.add(l.lower())
|
| 1261 |
clean.append(l)
|
|
|
|
| 1456 |
data.get("minute", 0) // 5, # Refresh every 5 min
|
| 1457 |
data.get("user_pattern", ""),
|
| 1458 |
data.get("audio", {}).get("type", ""),
|
| 1459 |
+
int(time.time()) // 90, # Throttle: at most one new generation ~90s
|
| 1460 |
]
|
| 1461 |
return hashlib.md5(str(key_parts).encode()).hexdigest()[:8]
|
| 1462 |
|
|
|
|
| 1552 |
|
| 1553 |
def start():
|
| 1554 |
agent.running = True
|
| 1555 |
+
# On HF the Gradio Timer drives the agent (ZeroGPU needs a request context);
|
| 1556 |
+
# only spin a background loop for the local hardware build.
|
| 1557 |
+
if not ON_HF:
|
| 1558 |
+
threading.Thread(target=agent.agent_loop, daemon=True).start()
|
| 1559 |
return f"Agent started ({LLM_MODE})"
|
| 1560 |
|
| 1561 |
def stop():
|
|
|
|
| 1636 |
"""One agent iteration driven by the Gradio Timer. On HF Spaces the LLM
|
| 1637 |
must be called from a request context (not a background thread) so ZeroGPU
|
| 1638 |
can allocate a GPU — that's what this provides. Returns dashboard outputs."""
|
| 1639 |
+
# Only consume GPU when explicitly running (Start button). Idle/abandoned
|
| 1640 |
+
# browser tabs just refresh the display and cost zero GPU.
|
| 1641 |
+
if not agent.running:
|
| 1642 |
+
return refresh_all()
|
| 1643 |
try:
|
| 1644 |
data = agent.collect_data()
|
| 1645 |
data["audio"] = agent.audio.get_context()
|