Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -292,7 +292,10 @@ def parse_model_output(text):
|
|
| 292 |
continue
|
| 293 |
action = canonicalize_action(candidate)
|
| 294 |
if action is not None:
|
| 295 |
-
note = str(
|
|
|
|
|
|
|
|
|
|
| 296 |
return action, note
|
| 297 |
final = (text or "").strip()
|
| 298 |
if final.startswith("```json"):
|
|
@@ -309,7 +312,10 @@ def parse_model_output(text):
|
|
| 309 |
if isinstance(args, dict):
|
| 310 |
action = canonicalize_action(args)
|
| 311 |
if action is not None:
|
| 312 |
-
note = str(
|
|
|
|
|
|
|
|
|
|
| 313 |
return action, note
|
| 314 |
return None, None
|
| 315 |
|
|
@@ -420,7 +426,16 @@ def describe_action(action, note):
|
|
| 420 |
return text
|
| 421 |
|
| 422 |
|
| 423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
def predict_next_action(
|
| 425 |
screenshot,
|
| 426 |
task,
|
|
|
|
| 292 |
continue
|
| 293 |
action = canonicalize_action(candidate)
|
| 294 |
if action is not None:
|
| 295 |
+
note = str(
|
| 296 |
+
candidate.get("note") or candidate.get("reasoning")
|
| 297 |
+
or candidate.get("reason") or ""
|
| 298 |
+
).strip()
|
| 299 |
return action, note
|
| 300 |
final = (text or "").strip()
|
| 301 |
if final.startswith("```json"):
|
|
|
|
| 312 |
if isinstance(args, dict):
|
| 313 |
action = canonicalize_action(args)
|
| 314 |
if action is not None:
|
| 315 |
+
note = str(
|
| 316 |
+
args.get("note") or args.get("reasoning")
|
| 317 |
+
or args.get("reason") or ""
|
| 318 |
+
).strip()
|
| 319 |
return action, note
|
| 320 |
return None, None
|
| 321 |
|
|
|
|
| 426 |
return text
|
| 427 |
|
| 428 |
|
| 429 |
+
def _estimate_duration(screenshot, *args, **kwargs):
|
| 430 |
+
"""ZeroGPU duration: measured 3.6s at 512 tokens non-thinking; thinking needs more."""
|
| 431 |
+
thinking = args[4] if len(args) > 4 else False
|
| 432 |
+
max_new_tokens = args[5] if len(args) > 5 else 512
|
| 433 |
+
if thinking:
|
| 434 |
+
return 90
|
| 435 |
+
return min(90, 20 + int(max_new_tokens) * 0.05)
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
@spaces.GPU(duration=_estimate_duration)
|
| 439 |
def predict_next_action(
|
| 440 |
screenshot,
|
| 441 |
task,
|