Spaces:
Sleeping
Sleeping
chenyicheng commited on
Commit ·
497280c
1
Parent(s): 6834f30
update app
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import re
|
|
| 5 |
import threading
|
| 6 |
from concurrent.futures import ThreadPoolExecutor, TimeoutError as FuturesTimeoutError
|
| 7 |
from typing import Any, Dict, List, Optional, Tuple
|
|
|
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
import logging
|
|
@@ -32,6 +33,8 @@ TRUNCATE_LIMIT = 400
|
|
| 32 |
PLAN_MAX_TOKENS = 16384
|
| 33 |
CODE_MAX_TOKENS = 8192
|
| 34 |
DATASET_PREVIEW_TIMEOUT = 60 # seconds
|
|
|
|
|
|
|
| 35 |
_DATASET_PREVIEW_CACHE: Dict[str, Dict] = {}
|
| 36 |
# Preset library
|
| 37 |
PRESETS = {
|
|
@@ -1119,6 +1122,40 @@ def _run_code(
|
|
| 1119 |
return _generate_code_from_plan(datasets, plan_text.strip())
|
| 1120 |
|
| 1121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1122 |
def _run_plan_and_code(
|
| 1123 |
task_description: str,
|
| 1124 |
benchmark_name: str,
|
|
@@ -1492,6 +1529,14 @@ def create_demo() -> gr.Blocks:
|
|
| 1492 |
interactive=False,
|
| 1493 |
lines=28
|
| 1494 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1495 |
|
| 1496 |
# --- Logic Binding ---
|
| 1497 |
preset_dropdown.change(
|
|
@@ -1510,6 +1555,13 @@ def create_demo() -> gr.Blocks:
|
|
| 1510 |
show_progress="hidden"
|
| 1511 |
)
|
| 1512 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1513 |
load_model_btn.click(_warmup_model, outputs=[]).then(get_status_text, outputs=[status_html])
|
| 1514 |
demo.load(_warmup_model, outputs=[]).then(get_status_text, outputs=[status_html])
|
| 1515 |
|
|
|
|
| 5 |
import threading
|
| 6 |
from concurrent.futures import ThreadPoolExecutor, TimeoutError as FuturesTimeoutError
|
| 7 |
from typing import Any, Dict, List, Optional, Tuple
|
| 8 |
+
import requests
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
import logging
|
|
|
|
| 33 |
PLAN_MAX_TOKENS = 16384
|
| 34 |
CODE_MAX_TOKENS = 8192
|
| 35 |
DATASET_PREVIEW_TIMEOUT = 60 # seconds
|
| 36 |
+
RUN_CODE_URL = os.getenv("DATACHEF_RUN_URL", "http://127.0.0.1:7001/run_code")
|
| 37 |
+
RUN_CODE_TIMEOUT = int(os.getenv("DATACHEF_RUN_TIMEOUT", "300"))
|
| 38 |
_DATASET_PREVIEW_CACHE: Dict[str, Dict] = {}
|
| 39 |
# Preset library
|
| 40 |
PRESETS = {
|
|
|
|
| 1122 |
return _generate_code_from_plan(datasets, plan_text.strip())
|
| 1123 |
|
| 1124 |
|
| 1125 |
+
def _execute_generated_code_remote(code_text: str, timeout: int = RUN_CODE_TIMEOUT) -> str:
|
| 1126 |
+
"""Send generated code to remote runner via proxy and return aggregated output."""
|
| 1127 |
+
if not code_text or not code_text.strip():
|
| 1128 |
+
return "No code to run. Please generate code first."
|
| 1129 |
+
try:
|
| 1130 |
+
resp = requests.post(
|
| 1131 |
+
RUN_CODE_URL,
|
| 1132 |
+
json={"code": code_text, "timeout": timeout},
|
| 1133 |
+
timeout=timeout + 10,
|
| 1134 |
+
)
|
| 1135 |
+
resp.raise_for_status()
|
| 1136 |
+
data = resp.json() if resp.content else {}
|
| 1137 |
+
except Exception as e:
|
| 1138 |
+
return f"Run error: {e}"
|
| 1139 |
+
|
| 1140 |
+
status = data.get("status", "unknown")
|
| 1141 |
+
retcode = data.get("returncode", "n/a")
|
| 1142 |
+
summary = data.get("summary", "")
|
| 1143 |
+
stdout = data.get("stdout", "")
|
| 1144 |
+
stderr = data.get("stderr", "")
|
| 1145 |
+
duration = data.get("duration_sec")
|
| 1146 |
+
|
| 1147 |
+
lines = [f"Status: {status} (returncode={retcode})"]
|
| 1148 |
+
if duration is not None:
|
| 1149 |
+
lines.append(f"Duration: {duration:.2f}s")
|
| 1150 |
+
if summary:
|
| 1151 |
+
lines.append(f"Summary: {summary}")
|
| 1152 |
+
if stdout:
|
| 1153 |
+
lines.append("\n--- stdout ---\n" + stdout)
|
| 1154 |
+
if stderr:
|
| 1155 |
+
lines.append("\n--- stderr ---\n" + stderr)
|
| 1156 |
+
return "\n".join(lines).strip()
|
| 1157 |
+
|
| 1158 |
+
|
| 1159 |
def _run_plan_and_code(
|
| 1160 |
task_description: str,
|
| 1161 |
benchmark_name: str,
|
|
|
|
| 1529 |
interactive=False,
|
| 1530 |
lines=28
|
| 1531 |
)
|
| 1532 |
+
run_code_btn = gr.Button("▶️ Run Code", variant="secondary", size="sm")
|
| 1533 |
+
run_output = gr.Code(
|
| 1534 |
+
value="",
|
| 1535 |
+
language="text",
|
| 1536 |
+
label=None,
|
| 1537 |
+
interactive=False,
|
| 1538 |
+
lines=16,
|
| 1539 |
+
)
|
| 1540 |
|
| 1541 |
# --- Logic Binding ---
|
| 1542 |
preset_dropdown.change(
|
|
|
|
| 1555 |
show_progress="hidden"
|
| 1556 |
)
|
| 1557 |
|
| 1558 |
+
run_code_btn.click(
|
| 1559 |
+
_execute_generated_code_remote,
|
| 1560 |
+
inputs=[code_out],
|
| 1561 |
+
outputs=[run_output],
|
| 1562 |
+
show_progress="hidden",
|
| 1563 |
+
)
|
| 1564 |
+
|
| 1565 |
load_model_btn.click(_warmup_model, outputs=[]).then(get_status_text, outputs=[status_html])
|
| 1566 |
demo.load(_warmup_model, outputs=[]).then(get_status_text, outputs=[status_html])
|
| 1567 |
|