ranranrunforit commited on
Commit
d098a15
·
verified ·
1 Parent(s): 87e4b2f

Upload 18 files

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py CHANGED
@@ -157,6 +157,52 @@ def ui_load_model(name):
157
  _SELFTEST = {"done": False, "result": ""}
158
 
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  def _export_dataset():
161
  n = finetune_data.count()
162
  if n == 0:
@@ -327,6 +373,17 @@ with gr.Blocks(title="Chan Compass · US", **_style_kw) as demo:
327
  auto_log = gr.Textbox(lines=14, label="Pipeline log (live — updates every 2s)",
328
  elem_id="detail-log")
329
  traces_md = gr.Markdown(research_agent.list_traces())
 
 
 
 
 
 
 
 
 
 
 
330
  auto_log_timer = gr.Timer(2.0)
331
 
332
  def _auto_tick():
 
157
  _SELFTEST = {"done": False, "result": ""}
158
 
159
 
160
+ def _publish_traces(repo_id: str):
161
+ """One-click: upload /data/traces to the Hub as a dataset, using the
162
+ HF_TOKEN secret. No command line needed."""
163
+ repo_id = (repo_id or "").strip()
164
+ if "/" not in repo_id:
165
+ return "⚠️ Enter a repo id like `username/dataset-name`."
166
+ token = (os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
167
+ or "").strip()
168
+ if not token:
169
+ return ("⚠️ No `HF_TOKEN` secret found. Add it in Space → Settings → "
170
+ "Variables and secrets (a **write** token), then try again.")
171
+ try:
172
+ import paths
173
+ traces = [f for f in os.listdir(paths.TRACES_DIR) if f.endswith(".json")]
174
+ except OSError:
175
+ traces = []
176
+ if not traces:
177
+ return "⚠️ No traces yet — run a few Auto Research reports first."
178
+ try:
179
+ from huggingface_hub import HfApi
180
+ api = HfApi(token=token)
181
+ api.create_repo(repo_id, repo_type="dataset", exist_ok=True)
182
+ # a small README so the dataset page explains itself
183
+ card = (
184
+ "---\nlicense: mit\ntags: [agent-trace, finance, chan-theory, llama-cpp]\n---\n\n"
185
+ "# Chan Compass — agent traces\n\n"
186
+ "JSON traces from the Chan Compass multi-agent research desk. Each file "
187
+ "is one ticker's run: the plan, every evidence-tool call and its result, "
188
+ "and each local sub-agent's request and response. Shared for the "
189
+ "Build Small hackathon (*Sharing is Caring*).\n\n"
190
+ "*Educational data — not investment advice.*\n")
191
+ import tempfile
192
+ rp = os.path.join(tempfile.gettempdir(), "README.md")
193
+ with open(rp, "w", encoding="utf-8") as f:
194
+ f.write(card)
195
+ api.upload_file(path_or_fileobj=rp, path_in_repo="README.md",
196
+ repo_id=repo_id, repo_type="dataset")
197
+ api.upload_folder(folder_path=paths.TRACES_DIR, path_in_repo="traces",
198
+ repo_id=repo_id, repo_type="dataset")
199
+ url = f"https://huggingface.co/datasets/{repo_id}"
200
+ return (f"✅ Published **{len(traces)}** trace(s) to [{repo_id}]({url}). "
201
+ f"Put that link in your submission for the *Sharing is Caring* badge.")
202
+ except Exception as e:
203
+ return f"❌ Upload failed: {e}"
204
+
205
+
206
  def _export_dataset():
207
  n = finetune_data.count()
208
  if n == 0:
 
373
  auto_log = gr.Textbox(lines=14, label="Pipeline log (live — updates every 2s)",
374
  elem_id="detail-log")
375
  traces_md = gr.Markdown(research_agent.list_traces())
376
+ gr.Markdown("**📡 Share traces** — publish every JSON agent trace in "
377
+ "`/data/traces` as a Hugging Face **dataset** (one click, uses "
378
+ "your `HF_TOKEN` secret — no command line). Earns *Sharing is "
379
+ "Caring*.", elem_classes=["s2-footnote"])
380
+ with gr.Row():
381
+ trace_repo = gr.Textbox(
382
+ value="ranranrunforit/chan-compass-agent-traces",
383
+ label="Dataset repo id", scale=3)
384
+ trace_pub = gr.Button("📡 Publish traces as dataset", scale=1)
385
+ trace_pub_status = gr.Markdown()
386
+ trace_pub.click(_publish_traces, trace_repo, trace_pub_status)
387
  auto_log_timer = gr.Timer(2.0)
388
 
389
  def _auto_tick():