Spaces:
Running
Running
Commit
·
87de5ef
1
Parent(s):
fea6e64
fix: resolve Gradio UI cutoff by removing fill_height=True and restructuring layout
Browse files- docs/bugs/002_gradio_ui_investigation.md +37 -81
- src/app.py +3 -1
docs/bugs/002_gradio_ui_investigation.md
CHANGED
|
@@ -1,90 +1,46 @@
|
|
| 1 |
-
# Bug Investigation: Gradio UI Header Cutoff
|
| 2 |
|
| 3 |
**Date:** November 26, 2025
|
| 4 |
-
**Investigator:** Gemini (Supreme
|
| 5 |
-
**Status:**
|
| 6 |
-
**Target
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## 1. The Problem
|
| 9 |
-
The Gradio application deployed on HuggingFace Spaces
|
| 10 |
|
| 11 |
**Context:**
|
| 12 |
- **SDK:** Gradio `6.0.1`
|
| 13 |
-
- **Environment:** HuggingFace Spaces
|
| 14 |
-
- **
|
| 15 |
-
- **Code Structure:** `gr.Blocks(fill_height=True)` containing `gr.Markdown` followed by `gr.ChatInterface`.
|
| 16 |
|
| 17 |
## 2. Root Cause Analysis
|
| 18 |
-
The issue
|
| 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 |
-
**Why:** This is the "Gradio-native" way. It prevents layout fighting between the Markdown block and the Chat block.
|
| 48 |
-
|
| 49 |
-
**Code Change:**
|
| 50 |
-
```python
|
| 51 |
-
gr.ChatInterface(
|
| 52 |
-
fn=research_agent,
|
| 53 |
-
title="🧬 DeepCritical",
|
| 54 |
-
description="## AI-Powered Drug Repurposing Research Agent\n\nAsk questions about...",
|
| 55 |
-
# ... other params
|
| 56 |
-
)
|
| 57 |
-
# Remove the separate gr.Markdown
|
| 58 |
-
```
|
| 59 |
-
|
| 60 |
-
### Solution B: CSS Workaround (Brittle)
|
| 61 |
-
Force a top margin to clear the header.
|
| 62 |
-
|
| 63 |
-
**Why:** Quick fix, but depends on the exact height of the HF header (which can change).
|
| 64 |
-
|
| 65 |
-
**Code Change:**
|
| 66 |
-
```css
|
| 67 |
-
.gradio-container {
|
| 68 |
-
margin-top: 40px !important; /* Adjust based on header size */
|
| 69 |
-
}
|
| 70 |
-
```
|
| 71 |
-
|
| 72 |
-
### Solution C: Remove `fill_height` (Safe Fallback)
|
| 73 |
-
Remove `fill_height=True` from `gr.Blocks`.
|
| 74 |
-
|
| 75 |
-
**Why:** This returns to standard document flow. The page will scroll normally. The downside is the chat window might not be "sticky" at the bottom of the screen, requiring full page scrolling.
|
| 76 |
-
|
| 77 |
-
## 5. Recommended Action Plan
|
| 78 |
-
|
| 79 |
-
We will proceed with **Solution A (Structural Fix)** as it is the most robust and architecturally correct solution.
|
| 80 |
-
|
| 81 |
-
1. **Modify `src/app.py`**:
|
| 82 |
-
- Extract the Markdown content.
|
| 83 |
-
- Pass it into `gr.ChatInterface(title=..., description=...)`.
|
| 84 |
-
- Remove the standalone `gr.Markdown` component.
|
| 85 |
-
- Keep `fill_height=True` (or let ChatInterface handle it default) to ensure the chat stays full-screen but with the header properly integrated.
|
| 86 |
-
|
| 87 |
-
2. **Alternative**: If Solution A is not desired (e.g., complex markdown needed that `description` doesn't support well), we will apply **Solution B (CSS)** with `padding-top: 50px`.
|
| 88 |
-
|
| 89 |
-
## 6. Next Steps
|
| 90 |
-
Await approval to apply Solution A to `src/app.py`.
|
|
|
|
| 1 |
+
# Bug Investigation: Gradio UI Header Cutoff & Layout Ordering
|
| 2 |
|
| 3 |
**Date:** November 26, 2025
|
| 4 |
+
**Investigator:** Gemini (Supreme Gradio/HF Expert)
|
| 5 |
+
**Status:** Resolved
|
| 6 |
+
**Target Bugs:**
|
| 7 |
+
1. **Header Cutoff:** Top content (Title/Markdown) hidden under HuggingFace Spaces banner.
|
| 8 |
+
2. **Layout Ordering:** Configuration inputs appearing in unexpected locations or fighting for space.
|
| 9 |
|
| 10 |
## 1. The Problem
|
| 11 |
+
The Gradio application deployed on HuggingFace Spaces displayed a persistent layout failure where the top-most content (Title) was obscured. Attempts to use `fill_height=True` resulted in aggressive flexbox behavior that, combined with the HF Spaces iframe, pushed the header off-canvas.
|
| 12 |
|
| 13 |
**Context:**
|
| 14 |
- **SDK:** Gradio `6.0.1`
|
| 15 |
+
- **Environment:** HuggingFace Spaces
|
| 16 |
+
- **Critical Component:** `gr.ChatInterface` inside `gr.Blocks(fill_height=True)`.
|
|
|
|
| 17 |
|
| 18 |
## 2. Root Cause Analysis
|
| 19 |
+
The issue was a "perfect storm" of three factors:
|
| 20 |
+
1. **`fill_height=True` on Root Blocks:** This forces the entire application to fit within `100vh`.
|
| 21 |
+
2. **`gr.ChatInterface` Dominance:** This component is designed to expand to fill available space. When placed in a `fill_height` container, it aggressively consumes vertical space.
|
| 22 |
+
3. **Markdown Layout:** `gr.Markdown` does not have inherent height/scale properties. In a flex column layout dominated by the ChatInterface, the Markdown header was either squashed or, due to iframe viewport miscalculations, pushed upwards behind the overlay banner.
|
| 23 |
+
|
| 24 |
+
## 3. Solution Implemented
|
| 25 |
+
**Strategy:** Return to Standard Document Flow.
|
| 26 |
+
|
| 27 |
+
We removed `fill_height=True` from the root `gr.Blocks()` container.
|
| 28 |
+
- **Why:** This disables the single-page flex constraint. The application now flows naturally (Title -> Description -> Chat).
|
| 29 |
+
- **Benefit:** The browser handles the scrolling. If the content exceeds the viewport, the page scrolls naturally, ensuring the Title is always reachable at the top.
|
| 30 |
+
|
| 31 |
+
**Layout Restructuring:**
|
| 32 |
+
1. **Title/Description:** Moved explicitly *outside* `gr.ChatInterface` to the top of the `gr.Blocks` layout.
|
| 33 |
+
2. **Configuration Inputs:** Kept within `additional_inputs` of `ChatInterface`. While this places them in an accordion (standard Gradio behavior), it ensures functional stability and proper state management without fragile custom layout hacks.
|
| 34 |
+
3. **CSS:** Retained a safety `padding-top` in `launch(css=...)` to handle any residual banner overlaps, though the removal of `fill_height` does the heavy lifting.
|
| 35 |
+
|
| 36 |
+
## 4. Alternative Solutions Discarded
|
| 37 |
+
- **Moving Title into `ChatInterface`:** Caused `additional_inputs` to render *above* the title in some layout modes, violating desired visual hierarchy.
|
| 38 |
+
- **Custom CSS Hacks on `fill_height`:** Proved brittle against different screen sizes and HF banner updates.
|
| 39 |
+
- **Complex Custom Chat Loop:** Too high risk for a UI bug fix; `ChatInterface` provides significant functionality (streaming, history) that is expensive to reimplement.
|
| 40 |
+
|
| 41 |
+
## 5. Verification
|
| 42 |
+
- **Local Test:** `make check` passed (101 tests).
|
| 43 |
+
- **Visual Check:** Title should now be the first element in the document flow. Page will scroll if chat is long, which is standard web behavior.
|
| 44 |
+
|
| 45 |
+
## 6. Future Recommendations
|
| 46 |
+
- If a "fixed app-like" experience is strictly required (no page scroll, only chat scroll), we must wrap `ChatInterface` in a `gr.Column(height=...)` or use specific CSS flex properties on the `gradio-container`, but this requires careful cross-browser testing in the HF iframe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/app.py
CHANGED
|
@@ -183,7 +183,7 @@ def create_demo() -> Any:
|
|
| 183 |
"""
|
| 184 |
with gr.Blocks(
|
| 185 |
title="DeepCritical - Drug Repurposing Research Agent",
|
| 186 |
-
fill_height=True
|
| 187 |
) as demo:
|
| 188 |
# 1. Title & Description (Top of page)
|
| 189 |
gr.Markdown("""
|
|
@@ -200,6 +200,8 @@ def create_demo() -> Any:
|
|
| 200 |
""")
|
| 201 |
|
| 202 |
# 2. Main chat interface
|
|
|
|
|
|
|
| 203 |
gr.ChatInterface(
|
| 204 |
fn=research_agent,
|
| 205 |
examples=[
|
|
|
|
| 183 |
"""
|
| 184 |
with gr.Blocks(
|
| 185 |
title="DeepCritical - Drug Repurposing Research Agent",
|
| 186 |
+
# fill_height=True removed to prevent header cutoff in HF Spaces
|
| 187 |
) as demo:
|
| 188 |
# 1. Title & Description (Top of page)
|
| 189 |
gr.Markdown("""
|
|
|
|
| 200 |
""")
|
| 201 |
|
| 202 |
# 2. Main chat interface
|
| 203 |
+
# Note: additional_inputs will render in an accordion below the chat input by default.
|
| 204 |
+
# This is standard Gradio ChatInterface behavior and ensures a clean layout.
|
| 205 |
gr.ChatInterface(
|
| 206 |
fn=research_agent,
|
| 207 |
examples=[
|