Spaces:
Sleeping

File size: 3,943 Bytes
a9de05b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# CollabCode β€” Local-Only Setup Guide

## Overview

CollabCode can run **completely locally** without requiring HuggingFace API credits or internet access for the core sectioning functionality. This guide shows you how to set it up.

## Requirements

- Python 3.13+ (or 3.10+)
- ~300 MB disk space (for dependencies)
- No API keys needed (local mode only)

## Quick Start

### 1. Activate the virtual environment

```bash
cd /Users/laramonteagudotubau/Documents/Script
source .venv/bin/activate
```

### 2. Run the app locally

```bash
bash run_local.sh
```

Or manually:

```bash
export LOCAL_SECTIONING=1
python app.py
```

The app will start on **http://localhost:7860**

## What Works Locally

βœ… **Agent 0 β€” Section Detection** (Heuristic)
- Identifies topical sections in transcripts
- No API calls required
- ~150,000 turns/second performance
- Produces same output format as remote LLM

## What Still Requires API

⚠️ **Agent 1a β€” Boundary Detection** β€” Uses HF Inference API
⚠️ **Agent 1b β€” Dimension Coding** β€” Uses HF Inference API  
⚠️ **Agent 2 β€” Rule Learning** β€” Uses HF Inference API

To use these agents, you'll need to:
1. Set `HF_TOKEN` environment variable with a valid HuggingFace token
2. Ensure your HuggingFace account has Inference API credits

## Performance Metrics (Heuristic Sectioning)

Based on test with 321-turn transcript:
- **Execution time**: 0.003 seconds
- **Throughput**: ~150,000 turns/second
- **Sections created**: 11
- **Memory overhead**: <10 MB

## Configuration Files

### .env.local
```
LOCAL_SECTIONING=1   # Enable heuristic fallback
HF_TOKEN=            # Empty = no API calls
DEBUG=1              # Verbose logging
```

### run_local.sh
Bash script that:
1. Activates the virtual environment
2. Loads `.env.local` configuration
3. Starts Gradio app on `localhost:7860`

## Efficiency Notes

The heuristic sectioning algorithm:

1. **Boundary Detection**: Looks for transition keywords in turn text:
   - "ok", "move on", "now", "let's", "debug", "fix", "test", "ready", "great"

2. **Section Balancing**: 
   - Target: ~30 turns per section
   - Minimum: 10 turns
   - Maximum: Flexible based on content

3. **Label Inference**:
   - Scans section text for keywords
   - Assigns phase labels: Planning, Debugging, Testing, Review
   - Falls back to "Phase N" if no keywords match

## Troubleshooting

### "Connection refused" error
The app expects Gradio to run on port 7860. If this port is taken:
```bash
python app.py --server_port 8000
```

### "No module named 'gradio'"
Make sure the virtual environment is activated:
```bash
source .venv/bin/activate
pip install -r requirements.txt
```

### "Section detection still calling HuggingFace"
Check that `LOCAL_SECTIONING=1` is set:
```bash
echo $LOCAL_SECTIONING
```

If empty, run:
```bash
source .env.local
```

## Next Steps

To fully localize the app:
1. Implement fallback for Agent 1a (boundary detection)
2. Implement fallback for Agent 1b (dimension coding)
3. Consider rule learning heuristics for Agent 2

See `agent0_sectioner.py` for fallback pattern examples.

## Technical Details

**Heuristic Algorithm** ([agent0_sectioner.py](agent0_sectioner.py)):

- `_boundary_score(turn)` β€” Rates turn likelihood of being section boundary
- `_heuristic_sections(turns)` β€” Groups turns into balanced sections
- `_turn_text()` β€” Formats turn for analysis
- `_BOUNDARY_PATTERNS` β€” Regex patterns for transition keywords

**Error Handling**:

When `run_sectioning()` is called:
1. Check `LOCAL_SECTIONING=1` environment variable
2. If set, use heuristic immediately (no API calls)
3. If not set, try remote LLM
4. On billing error, automatically fallback to heuristic
5. On other errors, raise exception

## Support

For questions about the heuristic algorithm:
- See docstring in `agent0_sectioner.py` (lines 1–50)
- See test results in `profile_results.json` (generated by `measure_efficiency.py`)