broadfield-dev commited on
Commit
a8d38e7
·
verified ·
1 Parent(s): 47624f7

Update bag.py

Browse files
Files changed (1) hide show
  1. bag.py +6 -190
bag.py CHANGED
@@ -2,6 +2,7 @@
2
  # All strings are exported as module-level variables for app.py to serve
3
 
4
  BASE_URL = "https://build-small-hackathon-overthinker.hf.space"
 
5
 
6
  # --- LLMs.txt ---
7
  LLMS_TXT = """# Overthinker: AI-Powered Decision Tree Explorer (WIP)
@@ -178,7 +179,7 @@ Overthinker_Hackathon/
178
 
179
  ## 🙌 Acknowledgments
180
 
181
- Built with ❤️ for the [Build Small Hackathon](https://build-small-hackathon-field-guide.hf.space/) by [Your Name].
182
 
183
  Special thanks to:
184
  - **Hugging Face** & **Gradio** for the platform and tools
@@ -295,12 +296,12 @@ VIDEO_PAGE_HTML = """<!DOCTYPE html>
295
  text-decoration: underline;
296
  }
297
  </style>
298
- </head>
299
  <body>
300
  <h1>Overthinker Demo</h1>
301
  <div class="video-container">
302
- <video controls poster="/static/poster.jpg">
303
- <source src="PLACEHOLDER_VIDEO_URL" type="video/mp4">
304
  Your browser does not support the video tag.
305
  </video>
306
  </div>
@@ -309,189 +310,4 @@ VIDEO_PAGE_HTML = """<!DOCTYPE html>
309
  </html>
310
  """
311
 
312
- README_MD="""
313
- # Overthinker: AI-Powered Decision Tree Explorer (WIP)
314
-
315
- **Overthinker** is an interactive decision tree explorer that helps you untangle complex choices by generating context-aware options and outcomes using a small open-weight AI model. Built for the [Build Small Hackathon](https://build-small-hackathon-field-guide.hf.space/) — a Hugging Face × Gradio jam for tiny AI models under 32B parameters.
316
-
317
- [![Hugging Face Space](https://img.shields.io/badge/🤗%20Hugging%20Face-Space-yellow)](https://huggingface.co/spaces/build-small-hackathon/overthinker)
318
- [![Demo Video](https://img.shields.io/badge/📺%20Demo-Video-blue)](https://youtube.com/)
319
- [![Social Post](https://img.shields.io/badge/🐦%20Social-Post-1DA1F2)](https://x.com/broadfield_dev/status/2066130027029406090)
320
-
321
- ![Screenshot](https://cdn-uploads.huggingface.co/production/uploads/677e884129c1f2af708eb07b/et2f8YT0mUp1DipL8LL-U.jpeg)
322
-
323
- ---
324
-
325
- ## 🧠 The Idea
326
-
327
- Ever spent hours overthinking a decision? Overthinker turns that into a feature. You start with a root question — "Should I quit my job?" — and the AI generates branching options (Input nodes) and outcomes (Outcome nodes), building a full decision tree. Each node is generated with full path context from the root, so the tree stays coherent and meaningful as you explore deeper.
328
-
329
- **Track:** Backyard AI (practical, problem-solving app) + Whimsical (Thousand Token Wood) — the playful tree exploration fits both.
330
-
331
- ---
332
-
333
- ## ✅ Hackathon Requirements Met
334
-
335
- | Requirement | Status | Details |
336
- |------------|--------|---------|
337
- | **Under 32B parameters** (REQ-01) | ✅ | Uses `nvidia/nemotron-3-nano-30b-a3b` (30B) via OpenRouter API |
338
- | **Gradio app deployed** (REQ-02) | ✅ | Gradio.Server-based app, deployable as Hugging Face Space |
339
- | **Demo video** (REQ-03) | ⏳ | Loading.... |
340
- | **Social post** (REQ-04) | ✅ | Linked above |
341
- | **GPU limit** (REQ-05) | ✅ | Zero GPU usage — inference runs remotely via OpenRouter API |
342
- | **Tagged README** (REQ-06) | ✅ | YAML front matter includes track + badge tags |
343
-
344
- ---
345
-
346
- ## 🏆 Targeted Prizes & Badges
347
-
348
- | Prize / Badge | Value | Why Overthinker Qualifies |
349
- |--------------|-------|--------------------------|
350
- | **Nemotron Hardware Prize** (NVIDIA) | Two RTX 5080s | Built with `nvidia/nemotron-3-nano-30b-a3b` — a Nemotron model. Full path context injection ensures coherent generation. |
351
- | **Off Brand** ($1,500) | Custom UI bonus | Custom D3.js tree visualization with zoom/pan/drag, path sidebar, export to SVG/JSON/PNG, keyboard shortcuts, theme toggle — far beyond default Gradio components. |
352
- | **Best Demo** ($1,000) | Full package | Interactive app + demo video + social post — all three will be polished. |
353
- | **Bonus Quest Champion** ($2,000) | Most criteria met | Targets Nemotron + Off Brand + Best Demo + Community Choice + Tiny Titan (model ≤ 4B? No, but 30B is still small). |
354
- | **Community Choice** ($2,000) | Shareable app | Beautiful D3 tree, export features, shareable trace upload to HF dataset — encourages social sharing. |
355
-
356
- ---
357
-
358
- ## ✨ Key Features
359
-
360
- - **Interactive Decision Tree**: Start with a root question, explore branching options and outcomes
361
- - **Full Path Context**: Every generation prompt includes the entire lineage from root to current node — no disconnected logic
362
- - **Session-Based Storage**: SQLite per-session databases — zero memory overlap between users, safe for public Spaces
363
- - **Rich Visualization**: D3.js tree with zoom, pan, drag, collapsible nodes, and breadcrumb navigation
364
- - **Export Options**: Save your tree as SVG, JSON, Markdown, or PNG
365
- - **Trace Upload**: Upload your decision tree to a shared Hugging Face dataset for community exploration
366
-
367
- ---
368
-
369
- ## 🛠️ Tech Stack
370
-
371
- | Component | Technology |
372
- |-----------|-----------|
373
- | **Frontend** | Gradio (custom D3.js + HTML/CSS/JS) |
374
- | **Backend** | Python 3.10+, Gradio.Server (FastAPI-based) |
375
- | **AI Model** | `nvidia/nemotron-3-nano-30b-a3b` via OpenRouter API |
376
- | **Database** | SQLite (per-session, disk-persistent) |
377
- | **Dataset** | Hugging Face `datasets` (trace upload) |
378
- | **Deployment** | Hugging Face Spaces (no GPU needed) |
379
-
380
- ---
381
-
382
- ## 🚀 Getting Started
383
-
384
- ### Local Development
385
-
386
- 1. **Clone the repository**
387
-
388
- ```bash
389
- git clone https://github.com/broadfield-dev/overthinker.git
390
- cd Overthinker_Hackathon
391
- ```
392
-
393
- 2. **Install dependencies**
394
-
395
- ```bash
396
- pip install gradio
397
- ```
398
-
399
- 3. **Set environment variables**
400
-
401
- Create a `.env` file:
402
-
403
- ```
404
- OPENROUTER_API_KEY=your_openrouter_api_key
405
- HF_TOKEN=your_huggingface_write_token # for trace upload
406
- HF_DATASET_REPO=your-username/overthinker-traces # optional, for trace sharing
407
- ```
408
-
409
- 4. **Run the app**
410
-
411
- ```bash
412
- python app.py
413
- ```
414
-
415
- Then open `http://localhost:7860` in your browser.
416
-
417
- ### Deploy on Hugging Face Spaces
418
-
419
- 1. Fork or upload this repository as a new Space on Hugging Face
420
- 2. Set the following **Secrets**:
421
- - `OPENROUTER_API_KEY`
422
- - `HF_TOKEN` (optional, for trace upload)
423
- - `HF_DATASET_REPO` (optional)
424
- 3. Ensure `requirements.txt` contains: `gradio`, `fastapi`, `uvicorn`, `httpx`, `jinja2`, `datasets`
425
- 4. The Space will start automatically — no GPU needed
426
-
427
- > Note: SQLite databases are stored in the `data/` directory, which persists across restarts on Hugging Face Spaces.
428
-
429
- ---
430
-
431
- ## 📚 How It Works
432
-
433
- 1. **Start**: Enter a decision question (e.g., "Should I start a business?")
434
- 2. **Generate Options**: Click "Explore Options" — the AI generates 3 possible paths
435
- 3. **Explore Outcomes**: Click any option to generate its potential outcomes
436
- 4. **Dive Deeper**: Continue exploring deeper into the tree — each level maintains full context from the root
437
- 5. **Export**: Save your tree as SVG, JSON, Markdown, or PNG
438
- 6. **Upload Trace**: Share your decision tree with the community via HF dataset upload
439
-
440
- ### Path Context Injection
441
-
442
- Overthinker passes the complete path from root to current node into every AI prompt:
443
-
444
- ```
445
- [ROOT] Should I quit my job? → [INPUT] Start freelancing → [OUTCOME] Income becomes unstable
446
- ```
447
-
448
- This ensures coherent, context-aware generation at every depth.
449
-
450
- ---
451
-
452
- ## 🧪 Testing & Quality
453
-
454
- - All endpoints tested with valid and invalid session IDs
455
- - Edge cases: empty trees, multiple concurrent users, API failures
456
- - Memory testing: validated <50MB RAM under heavy load (compared to 5GB in v26)
457
- - Frontend tested in Chrome, Firefox, and Safari
458
-
459
- ---
460
-
461
- ## 📦 File Structure
462
-
463
- ```
464
- Overthinker_Hackathon/
465
- ├── app.py # Backend with SQLite, POST endpoints, path context
466
- ├── templates/
467
- │ └── index.html # Full D3 tree visualization (~1800 lines)
468
- ├── data/ # Created automatically for per-session SQLite DBs
469
- ├── README.md # This file
470
- └── requirements.txt # (to be added — include gradio, fastapi, uvicorn, httpx, jinja2, datasets)
471
- ```
472
-
473
- ---
474
-
475
- ## 🔗 Links
476
-
477
- - **Field Guide**: [https://build-small-hackathon-field-guide.hf.space/](https://build-small-hackathon-field-guide.hf.space/)
478
- - **Hugging Face Space**: [To be added after submission](https://huggingface.co/spaces/build-small-hackathon/overthinker)
479
- - **Demo Video**: [To be added]()
480
- - **Social Post**: [To be added]()
481
- - **Hugging Face Dataset (Traces)**: [To be added]()
482
-
483
- ---
484
-
485
- ## 🙌 Acknowledgments
486
-
487
- Built with ❤️ for the [Build Small Hackathon](https://build-small-hackathon-field-guide.hf.space/) by [Your Name].
488
-
489
- Special thanks to:
490
- - **Hugging Face** & **Gradio** for the platform and tools
491
- - **NVIDIA** for the Nemotron model family
492
- - **OpenRouter** for providing API access to open-source models
493
- - **D3.js** for the powerful visualization library
494
-
495
- ---
496
-
497
- *Last updated: June 14, 2026*"""
 
2
  # All strings are exported as module-level variables for app.py to serve
3
 
4
  BASE_URL = "https://build-small-hackathon-overthinker.hf.space"
5
+ VIDEO_URL = "https://huggingface.co/spaces/build-small-hackathon/OverThinker/resolve/main/video_1.mp4"
6
 
7
  # --- LLMs.txt ---
8
  LLMS_TXT = """# Overthinker: AI-Powered Decision Tree Explorer (WIP)
 
179
 
180
  ## 🙌 Acknowledgments
181
 
182
+ Built with ❤️ for the [Build Small Hackathon](https://build-small-hackathon-field-guide.hf.space/) by broadfield-dev.
183
 
184
  Special thanks to:
185
  - **Hugging Face** & **Gradio** for the platform and tools
 
296
  text-decoration: underline;
297
  }
298
  </style>
299
+ </head>""" + f"""
300
  <body>
301
  <h1>Overthinker Demo</h1>
302
  <div class="video-container">
303
+ <video controls poster="https://cdn-uploads.huggingface.co/production/uploads/677e884129c1f2af708eb07b/et2f8YT0mUp1DipL8LL-U.jpeg">
304
+ <source src="{VIDEO_URL}" type="video/mp4">
305
  Your browser does not support the video tag.
306
  </video>
307
  </div>
 
310
  </html>
311
  """
312
 
313
+ README_MD=LLMS_TXT