VibecoderMcSwaggins commited on
Commit
8dc3e50
Β·
1 Parent(s): 8036817

fix: simplify Gradio UI to fit single viewport

Browse files

- Reduce header to 2 lines (title + one-line description)
- Remove MCP Tools tabs UI (MCP server still active at /gradio_api/mcp/)
- Simplify examples (just questions, no extra params shown)
- Minimal footer with disclaimer and MCP endpoint
- Remove unused mcp_tools imports from app.py

This fixes the header cutoff issue in HuggingFace Spaces iframe by
reducing total content to fit within standard viewport height.

Files changed (2) hide show
  1. docs/bugs/003_ui_viewport_redesign.md +173 -0
  2. src/app.py +20 -136
docs/bugs/003_ui_viewport_redesign.md ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Bug 003: UI Viewport Overflow - Redesign Required
2
+
3
+ **Date:** November 27, 2025
4
+ **Status:** Active
5
+ **Severity:** High (Demo UX)
6
+ **Related:** 001_gradio_ui_cutoff.md, 002_gradio_ui_investigation.md
7
+
8
+ ## Problem Summary
9
+
10
+ The Gradio UI has too much content to fit in a single viewport when embedded in HuggingFace Spaces iframe. The header gets cut off on initial load due to iframe rendering behavior.
11
+
12
+ **Key observation:** When user zooms out (cmd-), the iframe re-renders and everything becomes visible. This confirms it's a viewport/content overflow issue, not a pure CSS bug.
13
+
14
+ ## Current UI Elements (Top to Bottom)
15
+
16
+ ```
17
+ 1. Title: "DeepCritical"
18
+ 2. Subtitle: "AI-Powered Drug Repurposing Research Agent"
19
+ 3. Description paragraph
20
+ 4. Example questions (3 bullet points)
21
+ 5. Orchestrator Mode selector (simple/magentic)
22
+ 6. API Key input (BYOK)
23
+ 7. API Provider selector (openai/anthropic)
24
+ 8. Chatbot component (large)
25
+ 9. Examples table (4 rows with Mode, API Key, Provider columns)
26
+ 10. MCP Tools section header
27
+ 11. MCP Tools tabs (PubMed, Clinical Trials, Preprints, Search All, Analyze)
28
+ 12. Selected tool interface (Query input, Max Results slider, buttons)
29
+ 13. Footer disclaimer
30
+ ```
31
+
32
+ **Problem:** This is ~13 distinct UI sections. Too much for one screen.
33
+
34
+ ## What Changed Recently
35
+
36
+ | Component | Before | After | Purpose |
37
+ |-----------|--------|-------|---------|
38
+ | Orchestrator Mode | Not visible | simple/magentic toggle | Multi-agent support |
39
+ | API Key | Not visible | Text input (password) | BYOK for paid tiers |
40
+ | API Provider | Not visible | openai/anthropic toggle | Support both providers |
41
+ | Backend info | None | "Free Tier (HF Inference)" banner | User knows what's running |
42
+
43
+ These additions (BYOK, provider selection, mode selection) added ~100px+ of vertical space.
44
+
45
+ ## Root Cause Analysis
46
+
47
+ 1. **Iframe height constraint:** HF Spaces iframe has fixed viewport
48
+ 2. **Content overflow:** 13 sections exceed viewport height
49
+ 3. **Gradio ChatInterface:** Designed to fill available space, but when there's content above AND below, it can't calculate correctly
50
+ 4. **No scroll on initial load:** Iframe rendering doesn't trigger scroll to top
51
+
52
+ ## Redesign Options
53
+
54
+ ### Option A: Minimal Header (Recommended)
55
+
56
+ Remove redundant/verbose content. Keep only essentials above the chatbot.
57
+
58
+ ```
59
+ BEFORE (verbose):
60
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
61
+ β”‚ 🧬 DeepCritical β”‚
62
+ β”‚ AI-Powered Drug Repurposing Research... β”‚
63
+ β”‚ Ask questions about potential drug... β”‚
64
+ β”‚ Example questions: β”‚
65
+ β”‚ β€’ "What drugs could be repurposed..." β”‚
66
+ β”‚ β€’ "Is metformin effective..." β”‚
67
+ β”‚ β€’ "What existing medications..." β”‚
68
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
69
+ β”‚ Orchestrator Mode: [simple] [magentic] β”‚
70
+ β”‚ API Key: [____________] β”‚
71
+ β”‚ API Provider: [openai] [anthropic] β”‚
72
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
73
+ β”‚ Chatbot β”‚
74
+ β”‚ β”‚
75
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
76
+
77
+ AFTER (minimal):
78
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
79
+ β”‚ 🧬 DeepCritical - Drug Repurposing AI β”‚
80
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
81
+ β”‚ Chatbot β”‚
82
+ β”‚ β”‚
83
+ β”‚ β”‚
84
+ β”‚ β”‚
85
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
86
+ β”‚ βš™οΈ Settings (accordion - collapsed) β”‚
87
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
88
+ ```
89
+
90
+ **Changes:**
91
+ - One-line title (no subtitle/description)
92
+ - Examples ONLY in the chatbot examples feature (already there)
93
+ - Config in collapsed accordion (Gradio default for additional_inputs)
94
+ - Remove MCP Tools section entirely OR move to separate tab
95
+
96
+ ### Option B: Tabbed Interface
97
+
98
+ ```
99
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
100
+ β”‚ 🧬 DeepCritical β”‚
101
+ β”‚ [Chat] [MCP Tools] [About] β”‚
102
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
103
+ β”‚ β”‚
104
+ β”‚ (Selected tab content fills space) β”‚
105
+ β”‚ β”‚
106
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
107
+ ```
108
+
109
+ **Changes:**
110
+ - Title only
111
+ - Tabs for different features
112
+ - Chat tab: Just chatbot + collapsed config
113
+ - MCP Tools tab: The individual search interfaces
114
+ - About tab: Description, examples, links
115
+
116
+ ### Option C: Remove MCP Tools Section
117
+
118
+ The MCP Tools section (PubMed Search, Clinical Trials, etc.) duplicates functionality available through:
119
+ 1. The main chatbot (searches automatically)
120
+ 2. Claude Desktop via MCP protocol
121
+
122
+ **Rationale:** For a hackathon demo, users care about the CHAT experience. Power users can use MCP.
123
+
124
+ ```
125
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
126
+ β”‚ 🧬 DeepCritical - Drug Repurposing AI β”‚
127
+ β”‚ Ask about drug repurposing opportunitiesβ”‚
128
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
129
+ β”‚ Chatbot β”‚
130
+ β”‚ β”‚
131
+ β”‚ β”‚
132
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
133
+ β”‚ βš™οΈ Settings β–Ό β”‚
134
+ β”‚ (collapsed: mode, api key, provider) β”‚
135
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
136
+ β”‚ MCP: /gradio_api/mcp/ for Claude Desktopβ”‚
137
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
138
+ ```
139
+
140
+ ## Recommendation
141
+
142
+ **Option A + C combined:**
143
+
144
+ 1. **Minimal header:** One line title + one line description
145
+ 2. **Remove example bullets:** Keep only in ChatInterface examples feature
146
+ 3. **Keep config in accordion:** Already using `additional_inputs` (collapsed by default)
147
+ 4. **Remove MCP Tools UI:** Keep MCP server active, remove the tab interfaces
148
+ 5. **Minimal footer:** One line with MCP endpoint info
149
+
150
+ **Estimated vertical savings:** ~400px (should fit in single viewport)
151
+
152
+ ## Implementation Checklist
153
+
154
+ - [ ] Simplify gr.Markdown header to 2 lines max
155
+ - [ ] Remove MCP Tools gr.Tab section from UI
156
+ - [ ] Verify additional_inputs accordion is collapsed by default
157
+ - [ ] Add single-line footer with MCP endpoint
158
+ - [ ] Test in HF Spaces iframe at 100% zoom
159
+ - [ ] Test on mobile viewport
160
+
161
+ ## Files to Modify
162
+
163
+ ```
164
+ src/app.py - Main UI layout changes
165
+ ```
166
+
167
+ ## Success Criteria
168
+
169
+ - [ ] Full UI visible without scrolling at 100% zoom
170
+ - [ ] Header ("DeepCritical") always visible
171
+ - [ ] Chatbot functional
172
+ - [ ] Config accessible (in accordion)
173
+ - [ ] MCP still works (server active, just no UI tabs)
src/app.py CHANGED
@@ -11,13 +11,6 @@ from pydantic_ai.providers.anthropic import AnthropicProvider
11
  from pydantic_ai.providers.openai import OpenAIProvider
12
 
13
  from src.agent_factory.judges import HFInferenceJudgeHandler, JudgeHandler, MockJudgeHandler
14
- from src.mcp_tools import (
15
- analyze_hypothesis,
16
- search_all_sources,
17
- search_biorxiv,
18
- search_clinical_trials,
19
- search_pubmed,
20
- )
21
  from src.orchestrator_factory import create_orchestrator
22
  from src.tools.biorxiv import BioRxivTool
23
  from src.tools.clinicaltrials import ClinicalTrialsTool
@@ -202,168 +195,59 @@ def create_demo() -> Any:
202
  """
203
  with gr.Blocks(
204
  title="DeepCritical - Drug Repurposing Research Agent",
205
- # fill_height=True removed to prevent header cutoff in HF Spaces
206
  ) as demo:
207
- # 1. Title & Description (Top of page)
208
- gr.Markdown("""
209
- # 🧬 DeepCritical
210
- ## AI-Powered Drug Repurposing Research Agent
211
-
212
- Ask questions about potential drug repurposing opportunities.
213
- The agent searches PubMed, ClinicalTrials.gov, and bioRxiv/medRxiv preprints.
214
-
215
- **Example questions:**
216
- - "What drugs could be repurposed for Alzheimer's disease?"
217
- - "Is metformin effective for cancer treatment?"
218
- - "What existing medications show promise for Long COVID?"
219
- """)
220
-
221
- # 2. Main chat interface
222
- # Note: additional_inputs will render in an accordion below the chat input by default.
223
- # This is standard Gradio ChatInterface behavior and ensures a clean layout.
224
  gr.ChatInterface(
225
  fn=research_agent,
226
  examples=[
227
- [
228
- "What drugs could be repurposed for Alzheimer's disease?",
229
- "simple",
230
- "",
231
- "openai",
232
- ],
233
- [
234
- "Is metformin effective for treating cancer?",
235
- "simple",
236
- "",
237
- "openai",
238
- ],
239
- [
240
- "What medications show promise for Long COVID treatment?",
241
- "simple",
242
- "",
243
- "openai",
244
- ],
245
- [
246
- "Can statins be repurposed for neurological conditions?",
247
- "simple",
248
- "",
249
- "openai",
250
- ],
251
  ],
252
  additional_inputs=[
253
  gr.Radio(
254
  choices=["simple", "magentic"],
255
  value="simple",
256
- label="Orchestrator Mode",
257
- info="Simple: Linear (OpenAI/Anthropic) | Magentic: Multi-Agent (OpenAI)",
258
  ),
259
  gr.Textbox(
260
- label="πŸ”‘ API Key (Optional - Bring Your Own Key)",
261
  placeholder="sk-... or sk-ant-...",
262
  type="password",
263
- info="Enter your own API key for full AI analysis. Never stored.",
264
  ),
265
  gr.Radio(
266
  choices=["openai", "anthropic"],
267
  value="openai",
268
- label="API Provider",
269
- info="Select the provider for your API key",
270
  ),
271
  ],
272
  )
273
 
274
- # MCP Tool Interfaces (exposed via MCP protocol)
275
- gr.Markdown("---\n## MCP Tools (Also Available via Claude Desktop)")
276
-
277
- with gr.Tab("PubMed Search"):
278
- gr.Interface(
279
- fn=search_pubmed,
280
- inputs=[
281
- gr.Textbox(label="Query", placeholder="metformin alzheimer"),
282
- gr.Slider(1, 50, value=10, step=1, label="Max Results"),
283
- ],
284
- outputs=gr.Markdown(label="Results"),
285
- api_name="search_pubmed",
286
- )
287
-
288
- with gr.Tab("Clinical Trials"):
289
- gr.Interface(
290
- fn=search_clinical_trials,
291
- inputs=[
292
- gr.Textbox(label="Query", placeholder="diabetes phase 3"),
293
- gr.Slider(1, 50, value=10, step=1, label="Max Results"),
294
- ],
295
- outputs=gr.Markdown(label="Results"),
296
- api_name="search_clinical_trials",
297
- )
298
-
299
- with gr.Tab("Preprints"):
300
- gr.Interface(
301
- fn=search_biorxiv,
302
- inputs=[
303
- gr.Textbox(label="Query", placeholder="long covid treatment"),
304
- gr.Slider(1, 50, value=10, step=1, label="Max Results"),
305
- ],
306
- outputs=gr.Markdown(label="Results"),
307
- api_name="search_biorxiv",
308
- )
309
-
310
- with gr.Tab("Search All"):
311
- gr.Interface(
312
- fn=search_all_sources,
313
- inputs=[
314
- gr.Textbox(label="Query", placeholder="metformin cancer"),
315
- gr.Slider(1, 20, value=5, step=1, label="Max Per Source"),
316
- ],
317
- outputs=gr.Markdown(label="Results"),
318
- api_name="search_all",
319
- )
320
-
321
- with gr.Tab("Analyze Hypothesis"):
322
- gr.Interface(
323
- fn=analyze_hypothesis,
324
- inputs=[
325
- gr.Textbox(label="Drug", placeholder="metformin"),
326
- gr.Textbox(label="Condition", placeholder="Alzheimer's disease"),
327
- gr.Textbox(
328
- label="Evidence Summary",
329
- placeholder="Studies show metformin reduces tau phosphorylation...",
330
- lines=5,
331
- ),
332
- ],
333
- outputs=gr.Markdown(label="Analysis Result"),
334
- api_name="analyze_hypothesis",
335
- )
336
-
337
- gr.Markdown("""
338
- ---
339
- **Note**: This is a research tool and should not be used for medical decisions.
340
- Always consult healthcare professionals for medical advice.
341
-
342
- Built with PydanticAI + PubMed, ClinicalTrials.gov & bioRxiv
343
-
344
- **MCP Server**: Available at `/gradio_api/mcp/` for Claude Desktop integration
345
- """)
346
 
347
  return demo
348
 
349
 
350
  def main() -> None:
351
  """Run the Gradio app with MCP server enabled."""
352
- # CSS to fix the header cutoff issue in HuggingFace Spaces
353
- # Adds padding to the top of the container to clear the HF banner
354
- css = """
355
- .gradio-container {
356
- padding-top: 50px !important;
357
- }
358
- """
359
-
360
  demo = create_demo()
361
  demo.launch(
362
  server_name="0.0.0.0",
363
  server_port=7860,
364
  share=False,
365
  mcp_server=True,
366
- css=css,
367
  ssr_mode=False, # Fix for intermittent loading/hydration issues in HF Spaces
368
  )
369
 
 
11
  from pydantic_ai.providers.openai import OpenAIProvider
12
 
13
  from src.agent_factory.judges import HFInferenceJudgeHandler, JudgeHandler, MockJudgeHandler
 
 
 
 
 
 
 
14
  from src.orchestrator_factory import create_orchestrator
15
  from src.tools.biorxiv import BioRxivTool
16
  from src.tools.clinicaltrials import ClinicalTrialsTool
 
195
  """
196
  with gr.Blocks(
197
  title="DeepCritical - Drug Repurposing Research Agent",
 
198
  ) as demo:
199
+ # Minimal header (2 lines) to fit in single viewport
200
+ gr.Markdown(
201
+ "# 🧬 DeepCritical\n"
202
+ "*AI-powered drug repurposing research β€” searches PubMed, ClinicalTrials.gov & bioRxiv*"
203
+ )
204
+
205
+ # Main chat interface with config in collapsed accordion
 
 
 
 
 
 
 
 
 
 
206
  gr.ChatInterface(
207
  fn=research_agent,
208
  examples=[
209
+ ["What drugs could be repurposed for Alzheimer's disease?"],
210
+ ["Is metformin effective for treating cancer?"],
211
+ ["What medications show promise for Long COVID?"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  ],
213
  additional_inputs=[
214
  gr.Radio(
215
  choices=["simple", "magentic"],
216
  value="simple",
217
+ label="Mode",
218
+ info="Simple: Linear | Magentic: Multi-Agent (OpenAI only)",
219
  ),
220
  gr.Textbox(
221
+ label="API Key (Optional)",
222
  placeholder="sk-... or sk-ant-...",
223
  type="password",
224
+ info="Bring your own key for premium models. Never stored.",
225
  ),
226
  gr.Radio(
227
  choices=["openai", "anthropic"],
228
  value="openai",
229
+ label="Provider",
 
230
  ),
231
  ],
232
  )
233
 
234
+ # Minimal footer
235
+ gr.Markdown(
236
+ "*Research tool only β€” not for medical decisions. " "MCP: `/gradio_api/mcp/`*",
237
+ elem_classes=["footer"],
238
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
 
240
  return demo
241
 
242
 
243
  def main() -> None:
244
  """Run the Gradio app with MCP server enabled."""
 
 
 
 
 
 
 
 
245
  demo = create_demo()
246
  demo.launch(
247
  server_name="0.0.0.0",
248
  server_port=7860,
249
  share=False,
250
  mcp_server=True,
 
251
  ssr_mode=False, # Fix for intermittent loading/hydration issues in HF Spaces
252
  )
253