VibecoderMcSwaggins commited on
Commit
70cda69
Β·
1 Parent(s): 580b270

docs: Rewrite SPEC-22 with principled engineering rationale

Browse files

- Document why gr.Progress doesn't work with ChatInterface (GitHub #5967)
- Explain why gr.Blocks refactor would be over-engineering
- Specify exact fix: remove gr.Progress, add show_progress="full"
- Include verification steps and acceptance criteria

docs/specs/SPEC-22-PROGRESS-BAR-REMOVAL.md CHANGED
@@ -1,127 +1,151 @@
1
- # SPEC-22: Progress Bar Removal
2
 
3
  **Status:** READY FOR IMPLEMENTATION
4
- **Priority:** P3 (Cosmetic UX fix)
5
  **Effort:** 15 minutes
6
  **PR Scope:** Single file fix
7
 
8
  ---
9
 
10
- ## Problem Statement
11
 
12
- The `gr.Progress()` bar conflicts with Gradio's `ChatInterface`, causing visual glitches:
13
- - Progress bar "floats" in the middle of chat output
14
- - Text overlaps with progress bar
15
- - Looks unprofessional
16
-
17
- **Root Cause:** `gr.Progress()` is designed for `gr.Interface`, not `ChatInterface`. It's a known Gradio limitation.
18
 
19
  ---
20
 
21
- ## Current Code (BROKEN)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  ```python
24
- # src/app.py - research_agent function
25
- async def research_agent(
26
- message: str,
27
- history: list[dict[str, Any]],
28
- domain: str = "sexual_health",
29
- api_key: str = "",
30
- api_key_state: str = "",
31
- progress: gr.Progress = gr.Progress(), # ← PROBLEM: Causes visual glitches
32
- ) -> AsyncGenerator[str, None]:
33
- ...
34
- if event.type == "started":
35
- progress(0, desc="Starting research...") # ← These cause overlap
36
- elif event.type == "progress":
37
- progress(p, desc=event.message)
38
  ```
39
 
 
 
40
  ---
41
 
42
- ## Required Fix
43
 
44
- Remove `gr.Progress()` entirely. We already have emoji status messages in chat output.
45
 
46
  ```python
47
- # src/app.py - Fixed version
48
- async def research_agent(
49
- message: str,
50
- history: list[dict[str, Any]],
51
- domain: str = "sexual_health",
52
- api_key: str = "",
53
- api_key_state: str = "",
54
- # REMOVED: progress: gr.Progress = gr.Progress(),
55
- ) -> AsyncGenerator[str, None]:
56
- ...
57
- # REMOVED: All progress(...) calls
58
 
59
- # KEEP: Emoji status messages are already being yielded
60
- # These work great with ChatInterface:
61
- # yield "⏱️ **PROGRESS**: Round 1/5 (~3m 0s remaining)"
 
62
  ```
63
 
64
- ---
65
 
66
- ## Implementation Checklist
67
-
68
- - [ ] Open `src/app.py`
69
- - [ ] Remove `progress: gr.Progress = gr.Progress()` from `research_agent` signature
70
- - [ ] Remove all `progress(...)` calls inside `research_agent`
71
- - [ ] Verify emoji status yields are still present (they should be)
72
- - [ ] Run `uv run python -c "from src.app import create_demo; print('OK')"`
73
- - [ ] Run `make check`
74
- - [ ] Test locally: `uv run python src/app.py` and verify no floating progress bar
75
 
76
  ---
77
 
78
- ## What We Keep
79
 
80
- The emoji status messages in chat output:
81
 
82
- ```
83
- ⏱️ **PROGRESS**: Round 1/5 (~3m 0s remaining)
84
- πŸ”¬ **Step 2: SearchAgent** - Searching for evidence...
85
- βœ… **COMPLETE**: Research finished in 45 seconds
86
- ```
87
 
88
- These are yielded directly to chat and work perfectly with `ChatInterface`.
 
 
 
 
 
 
 
89
 
90
- ---
 
 
91
 
92
- ## Acceptance Criteria
93
 
94
- 1. No `gr.Progress()` in `research_agent` function signature
95
- 2. No `progress(...)` calls in `research_agent` function body
96
- 3. Emoji status messages still appear in chat output
97
- 4. No floating/overlapping progress bar in UI
98
- 5. `make check` passes
99
 
100
  ---
101
 
102
- ## Dependencies
103
 
104
- None. This is a standalone cosmetic fix.
 
 
 
 
 
 
105
 
106
  ---
107
 
108
- ## Testing
109
 
110
  ```bash
111
- # Start local server
112
- uv run python src/app.py
113
-
114
- # In browser:
115
- # 1. Submit a research query
116
- # 2. Verify NO floating progress bar appears
117
- # 3. Verify emoji status messages DO appear in chat
118
- # 4. Verify chat messages don't have visual glitches
119
  ```
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  ---
122
 
123
- ## Notes
124
 
125
- - This is the recommended fix from Gradio's own documentation
126
- - `ChatInterface.show_progress="minimal"` (default) still shows a spinner, which is fine
127
- - If we need a real progress bar later, we'd need to refactor to `gr.Blocks` wrapper
 
1
+ # SPEC-22: Remove Unsupported gr.Progress from ChatInterface
2
 
3
  **Status:** READY FOR IMPLEMENTATION
4
+ **Priority:** P3 (Technical debt cleanup)
5
  **Effort:** 15 minutes
6
  **PR Scope:** Single file fix
7
 
8
  ---
9
 
10
+ ## Executive Summary
11
 
12
+ We are using `gr.Progress()` with `gr.ChatInterface`, but **Gradio does not support this combination**. This is not a workaround - this is the correct fix to align with Gradio's architecture.
 
 
 
 
 
13
 
14
  ---
15
 
16
+ ## Technical Background
17
+
18
+ ### Gradio's Progress Mechanisms
19
+
20
+ | Mechanism | Designed For | Works With ChatInterface |
21
+ |-----------|--------------|-------------------------|
22
+ | `gr.Progress()` | `gr.Interface` | ❌ NO - causes visual glitches |
23
+ | `show_progress` param | `ChatInterface` | βœ… YES - built-in spinner/timer |
24
+ | Streaming yields | `ChatInterface` | βœ… YES - native support |
25
+ | `ChatMessage.metadata.status` | `ChatInterface` | βœ… YES - per-message indicators |
26
+
27
+ ### Why gr.Progress Fails with ChatInterface
28
+
29
+ 1. **GitHub Issue [#5967](https://github.com/gradio-app/gradio/issues/5967)**: "gr.Progress is not integrated with ChatInterface or Chatbots" - closed without resolution (Jan 2024)
30
+ 2. **Visual symptoms**: Progress bar floats in middle of chat output, overlaps text
31
+ 3. **Root cause**: `gr.Progress` injects UI into the output component area, but `ChatInterface` manages its own output rendering
32
+
33
+ ### What We Already Have (Working)
34
+
35
+ Our `research_agent` function already yields semantic status messages:
36
 
37
  ```python
38
+ yield "🧠 **Backend**: Paid API (OpenAI) | **Domain**: Sexual Health"
39
+ yield "⏳ **Processing...** Searching PubMed, ClinicalTrials.gov..."
40
+ # During orchestration:
41
+ yield "⏱️ **PROGRESS**: Round 1/5 (~3m 0s remaining)"
42
+ yield "πŸ”¬ **Step 2: SearchAgent** - Searching for evidence..."
43
+ yield "βœ… **COMPLETE**: Research finished"
 
 
 
 
 
 
 
 
44
  ```
45
 
46
+ These work perfectly with ChatInterface streaming.
47
+
48
  ---
49
 
50
+ ## The Fix
51
 
52
+ ### What to Remove
53
 
54
  ```python
55
+ # src/app.py - REMOVE from research_agent signature:
56
+ progress: gr.Progress = gr.Progress(), # noqa: B008
 
 
 
 
 
 
 
 
 
57
 
58
+ # src/app.py - REMOVE all progress() calls:
59
+ progress(0, desc="Starting research...")
60
+ progress(0.1, desc="Multi-agent reasoning...")
61
+ progress(p, desc=event.message)
62
  ```
63
 
64
+ ### What to Add (Optional Enhancement)
65
 
66
+ ```python
67
+ # src/app.py - In create_demo(), add show_progress for built-in spinner:
68
+ demo = gr.ChatInterface(
69
+ fn=research_agent,
70
+ show_progress="full", # Shows spinner + runtime timer (Gradio native)
71
+ ...
72
+ )
73
+ ```
 
74
 
75
  ---
76
 
77
+ ## Why This Is The Correct Approach (Not A Workaround)
78
 
79
+ ### ❌ What Would Be Over-Engineering
80
 
81
+ Refactoring from `ChatInterface` to `gr.Blocks` + `gr.Chatbot` just to support `gr.Progress`:
 
 
 
 
82
 
83
+ | ChatInterface provides FREE | gr.Blocks would require manual |
84
+ |---------------------------|-------------------------------|
85
+ | MCP server support | Unknown if compatible |
86
+ | Chat history state | Manual `gr.State` management |
87
+ | Submit/Stop buttons | Manual button wiring |
88
+ | Example handling | Manual click handlers |
89
+ | Streaming support | Manual async iteration |
90
+ | Accordion for inputs | Manual accordion component |
91
 
92
+ **Effort**: Days of refactoring + testing
93
+ **Benefit**: A progress bar (which we already have via emoji status)
94
+ **Verdict**: Not justified
95
 
96
+ ### βœ… What Is Professional Engineering
97
 
98
+ 1. Use `ChatInterface` as designed (high-level, batteries-included)
99
+ 2. Remove unsupported feature (`gr.Progress`)
100
+ 3. Rely on supported mechanisms:
101
+ - Streaming status yields (already implemented)
102
+ - `show_progress="full"` (Gradio native)
103
 
104
  ---
105
 
106
+ ## Implementation Checklist
107
 
108
+ - [ ] Open `src/app.py`
109
+ - [ ] Remove `progress: gr.Progress = gr.Progress()` from `research_agent` signature
110
+ - [ ] Remove all `progress(...)` calls (lines 192, 194, 204)
111
+ - [ ] Add `show_progress="full"` to `gr.ChatInterface` constructor
112
+ - [ ] Verify emoji status yields still present in orchestrator events
113
+ - [ ] Run `make check`
114
+ - [ ] Test locally: `uv run python src/app.py`
115
 
116
  ---
117
 
118
+ ## Verification
119
 
120
  ```bash
121
+ # Verify no gr.Progress usage
122
+ grep -n "gr.Progress\|progress(" src/app.py
123
+
124
+ # Should return empty (no matches)
 
 
 
 
125
  ```
126
 
127
+ ### Manual Test
128
+ 1. Start app: `uv run python src/app.py`
129
+ 2. Submit a research query
130
+ 3. Verify:
131
+ - βœ… Gradio spinner appears (top-right timer)
132
+ - βœ… Emoji status messages stream in chat
133
+ - ❌ No floating/overlapping progress bar
134
+
135
+ ---
136
+
137
+ ## Acceptance Criteria
138
+
139
+ 1. No `gr.Progress` in codebase
140
+ 2. `show_progress="full"` added to ChatInterface
141
+ 3. Emoji status messages continue working
142
+ 4. No visual glitches in UI
143
+ 5. `make check` passes
144
+
145
  ---
146
 
147
+ ## References
148
 
149
+ - [Gradio ChatInterface Docs](https://www.gradio.app/docs/gradio/chatinterface)
150
+ - [Gradio Progress Bars Guide](https://www.gradio.app/guides/progress-bars)
151
+ - [GitHub #5967: Progress bar for ChatInterface](https://github.com/gradio-app/gradio/issues/5967)