Remove model status and run-complete banner
Browse files
app.py
CHANGED
|
@@ -16,16 +16,11 @@ from config import ADAPTER_MODEL, AGENT_MAX_STEPS, DATA_DIR
|
|
| 16 |
from examples import DEMO_DATASETS, DEMO_EXAMPLES
|
| 17 |
|
| 18 |
MODEL, TOKENIZER = None, None
|
| 19 |
-
MODEL_STATUS = "⏳ Model not loaded yet"
|
| 20 |
STORY_URL = "https://datasense-e2b.netlify.app/"
|
| 21 |
LINKEDIN_POST_URL = (
|
| 22 |
"https://www.linkedin.com/posts/sanjaymalladi_buildsmall-huggingface-modal-share-7471993638814654464-47hY/"
|
| 23 |
)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
def get_model_status() -> str:
|
| 27 |
-
return MODEL_STATUS
|
| 28 |
-
|
| 29 |
CUSTOM_CSS = """
|
| 30 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,600;1,6..72,400&display=swap');
|
| 31 |
|
|
@@ -66,15 +61,6 @@ CUSTOM_CSS = """
|
|
| 66 |
padding: 0.2rem 0.65rem;
|
| 67 |
margin-bottom: 0.75rem;
|
| 68 |
}
|
| 69 |
-
#ds-status {
|
| 70 |
-
font-family: 'IBM Plex Mono', monospace;
|
| 71 |
-
font-size: 0.85rem;
|
| 72 |
-
background: var(--ds-surface);
|
| 73 |
-
border-left: 3px solid var(--ds-accent);
|
| 74 |
-
padding: 0.65rem 1rem;
|
| 75 |
-
border-radius: 0 8px 8px 0;
|
| 76 |
-
margin-bottom: 1rem;
|
| 77 |
-
}
|
| 78 |
#ds-panel {
|
| 79 |
background: var(--ds-surface);
|
| 80 |
border: 1px solid var(--ds-border);
|
|
@@ -117,12 +103,11 @@ def build_theme() -> gr.Theme:
|
|
| 117 |
|
| 118 |
|
| 119 |
def _load_model():
|
| 120 |
-
global MODEL, TOKENIZER
|
| 121 |
if MODEL is None or TOKENIZER is None:
|
| 122 |
from model_loader import load_model_and_tokenizer
|
| 123 |
|
| 124 |
MODEL, TOKENIZER = load_model_and_tokenizer()
|
| 125 |
-
MODEL_STATUS = f"✅ **SFT v1 ready** — `{ADAPTER_MODEL}`"
|
| 126 |
return MODEL, TOKENIZER
|
| 127 |
|
| 128 |
|
|
@@ -155,15 +140,14 @@ def run_task(
|
|
| 155 |
max_steps: int,
|
| 156 |
progress=gr.Progress(),
|
| 157 |
):
|
| 158 |
-
empty = ("", "")
|
| 159 |
if not task.strip():
|
| 160 |
-
return "⚠️ Enter a task question.",
|
| 161 |
|
| 162 |
progress(0.05, desc="Resolving dataset…")
|
| 163 |
data_path = _resolve_data_path(data_mode, dataset_name, upload_file)
|
| 164 |
if data_path is None:
|
| 165 |
msg = "⚠️ Upload a `.csv` file first." if data_mode == "Upload your CSV" else f"⚠️ Dataset not found: {dataset_name}"
|
| 166 |
-
return msg,
|
| 167 |
|
| 168 |
try:
|
| 169 |
progress(0.15, desc="Loading Gemma-4 + SFT LoRA…")
|
|
@@ -178,32 +162,18 @@ def run_task(
|
|
| 178 |
progress=progress,
|
| 179 |
)
|
| 180 |
except Exception as exc:
|
| 181 |
-
return f"**Error:** {exc}",
|
| 182 |
|
| 183 |
answer_block = f"## {result['answer']}" if result["answer"] else "_Could not parse an answer — check the execution trace._"
|
| 184 |
if result.get("summary"):
|
| 185 |
answer_block += f"\n\n{result['summary']}"
|
| 186 |
-
status = (
|
| 187 |
-
f"✅ **Live inference complete** — `{data_path.name}` · "
|
| 188 |
-
f"{int(max_steps)} max steps · real model + sandbox execution (not canned)"
|
| 189 |
-
)
|
| 190 |
|
| 191 |
-
return
|
| 192 |
-
status,
|
| 193 |
-
answer_block,
|
| 194 |
-
result["steps_markdown"],
|
| 195 |
-
)
|
| 196 |
|
| 197 |
|
| 198 |
@spaces.GPU(duration=300)
|
| 199 |
def preload_model():
|
| 200 |
-
|
| 201 |
-
MODEL_STATUS = "⏳ Loading Gemma-4 + SFT LoRA on GPU…"
|
| 202 |
-
try:
|
| 203 |
-
_load_model()
|
| 204 |
-
except Exception as exc:
|
| 205 |
-
MODEL_STATUS = f"⚠️ **Model load failed:** {exc}"
|
| 206 |
-
raise
|
| 207 |
|
| 208 |
|
| 209 |
def build_ui() -> gr.Blocks:
|
|
@@ -216,7 +186,6 @@ def build_ui() -> gr.Blocks:
|
|
| 216 |
"""
|
| 217 |
# DataSense E2B
|
| 218 |
**Live inference** — Gemma-4 2B + SFT v1 writes Python, runs it on your CSV, reads real stdout/errors.
|
| 219 |
-
Not canned responses; each run is a fresh agent loop on GPU.
|
| 220 |
"""
|
| 221 |
)
|
| 222 |
gr.Markdown(
|
|
@@ -225,8 +194,6 @@ Not canned responses; each run is a fresh agent loop on GPU.
|
|
| 225 |
f"LoRA [`DataSense-Modal-E2B-SFT`](https://huggingface.co/{ADAPTER_MODEL})",
|
| 226 |
)
|
| 227 |
|
| 228 |
-
model_status = gr.Markdown(get_model_status(), elem_id="ds-status")
|
| 229 |
-
|
| 230 |
with gr.Row(equal_height=False):
|
| 231 |
with gr.Column(scale=4, elem_id="ds-panel"):
|
| 232 |
gr.Markdown("### Configure")
|
|
@@ -274,7 +241,6 @@ Not canned responses; each run is a fresh agent loop on GPU.
|
|
| 274 |
)
|
| 275 |
|
| 276 |
with gr.Column(scale=6):
|
| 277 |
-
run_status = gr.Markdown("_Ready — click Run to start live inference._", elem_id="ds-status")
|
| 278 |
with gr.Tabs():
|
| 279 |
with gr.Tab("✅ Answer"):
|
| 280 |
answer_out = gr.Markdown()
|
|
@@ -286,11 +252,9 @@ Not canned responses; each run is a fresh agent loop on GPU.
|
|
| 286 |
run_btn.click(
|
| 287 |
fn=run_task,
|
| 288 |
inputs=[data_mode, dataset, upload, task, max_steps],
|
| 289 |
-
outputs=[
|
| 290 |
show_progress="full",
|
| 291 |
-
)
|
| 292 |
-
|
| 293 |
-
demo.load(fn=get_model_status, outputs=model_status)
|
| 294 |
|
| 295 |
return demo
|
| 296 |
|
|
|
|
| 16 |
from examples import DEMO_DATASETS, DEMO_EXAMPLES
|
| 17 |
|
| 18 |
MODEL, TOKENIZER = None, None
|
|
|
|
| 19 |
STORY_URL = "https://datasense-e2b.netlify.app/"
|
| 20 |
LINKEDIN_POST_URL = (
|
| 21 |
"https://www.linkedin.com/posts/sanjaymalladi_buildsmall-huggingface-modal-share-7471993638814654464-47hY/"
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
CUSTOM_CSS = """
|
| 25 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,600;1,6..72,400&display=swap');
|
| 26 |
|
|
|
|
| 61 |
padding: 0.2rem 0.65rem;
|
| 62 |
margin-bottom: 0.75rem;
|
| 63 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
#ds-panel {
|
| 65 |
background: var(--ds-surface);
|
| 66 |
border: 1px solid var(--ds-border);
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
def _load_model():
|
| 106 |
+
global MODEL, TOKENIZER
|
| 107 |
if MODEL is None or TOKENIZER is None:
|
| 108 |
from model_loader import load_model_and_tokenizer
|
| 109 |
|
| 110 |
MODEL, TOKENIZER = load_model_and_tokenizer()
|
|
|
|
| 111 |
return MODEL, TOKENIZER
|
| 112 |
|
| 113 |
|
|
|
|
| 140 |
max_steps: int,
|
| 141 |
progress=gr.Progress(),
|
| 142 |
):
|
|
|
|
| 143 |
if not task.strip():
|
| 144 |
+
return "⚠️ Enter a task question.", ""
|
| 145 |
|
| 146 |
progress(0.05, desc="Resolving dataset…")
|
| 147 |
data_path = _resolve_data_path(data_mode, dataset_name, upload_file)
|
| 148 |
if data_path is None:
|
| 149 |
msg = "⚠️ Upload a `.csv` file first." if data_mode == "Upload your CSV" else f"⚠️ Dataset not found: {dataset_name}"
|
| 150 |
+
return msg, ""
|
| 151 |
|
| 152 |
try:
|
| 153 |
progress(0.15, desc="Loading Gemma-4 + SFT LoRA…")
|
|
|
|
| 162 |
progress=progress,
|
| 163 |
)
|
| 164 |
except Exception as exc:
|
| 165 |
+
return f"**Error:** {exc}", ""
|
| 166 |
|
| 167 |
answer_block = f"## {result['answer']}" if result["answer"] else "_Could not parse an answer — check the execution trace._"
|
| 168 |
if result.get("summary"):
|
| 169 |
answer_block += f"\n\n{result['summary']}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
+
return answer_block, result["steps_markdown"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
|
| 174 |
@spaces.GPU(duration=300)
|
| 175 |
def preload_model():
|
| 176 |
+
_load_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
|
| 179 |
def build_ui() -> gr.Blocks:
|
|
|
|
| 186 |
"""
|
| 187 |
# DataSense E2B
|
| 188 |
**Live inference** — Gemma-4 2B + SFT v1 writes Python, runs it on your CSV, reads real stdout/errors.
|
|
|
|
| 189 |
"""
|
| 190 |
)
|
| 191 |
gr.Markdown(
|
|
|
|
| 194 |
f"LoRA [`DataSense-Modal-E2B-SFT`](https://huggingface.co/{ADAPTER_MODEL})",
|
| 195 |
)
|
| 196 |
|
|
|
|
|
|
|
| 197 |
with gr.Row(equal_height=False):
|
| 198 |
with gr.Column(scale=4, elem_id="ds-panel"):
|
| 199 |
gr.Markdown("### Configure")
|
|
|
|
| 241 |
)
|
| 242 |
|
| 243 |
with gr.Column(scale=6):
|
|
|
|
| 244 |
with gr.Tabs():
|
| 245 |
with gr.Tab("✅ Answer"):
|
| 246 |
answer_out = gr.Markdown()
|
|
|
|
| 252 |
run_btn.click(
|
| 253 |
fn=run_task,
|
| 254 |
inputs=[data_mode, dataset, upload, task, max_steps],
|
| 255 |
+
outputs=[answer_out, steps_out],
|
| 256 |
show_progress="full",
|
| 257 |
+
)
|
|
|
|
|
|
|
| 258 |
|
| 259 |
return demo
|
| 260 |
|