File size: 7,337 Bytes
b7f3196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# Medical Q&A Bot - UI Implementation Summary

## πŸ“¦ What Was Added

### New Files Created:

1. **`app.py`** - Main Gradio web interface (RECOMMENDED)
   - Clean, modern UI with gradient header
   - Dual-view mode (formatted HTML + JSON)
   - Real-time classification and retrieval
   - Example queries built-in
   - Automatic API generation

2. **`app_streamlit.py`** - Alternative Streamlit interface

   - Interactive sidebar with settings

   - Card-based result display

   - Progress bars for confidence scores

   - More customizable styling options



3. **`QUICKSTART.md`** - Step-by-step setup guide

   - Installation instructions

   - How to launch both UIs

   - Troubleshooting tips

   - Demo tips for presentations



4. **`UI_README.md`** - Comprehensive documentation
   - Feature descriptions
   - Configuration options
   - Advanced usage
   - API information

5. **`setup_ui.py`** - Automated setup script

   - Installs all dependencies

   - Checks for required data files

   - Verifies setup completeness



### Modified Files:



1. **`requirements.txt`** - Added:

   - `gradio` - Main UI framework

   - `streamlit` - Alternative UI framework



## 🎯 Key Features



### Classification Display

- βœ… Shows query type (Medical/Administrative/Other)

- βœ… Confidence scores with visual indicators

- βœ… Color-coded results



### Document Retrieval

- βœ… Retrieves top N relevant documents (1-50)

- βœ… Shows BM25, Dense, and RRF scores

- βœ… Displays document preview with full metadata

- βœ… Optional reranker for better accuracy



### User Experience

- βœ… Clean, professional design

- βœ… Example queries for easy testing

- βœ… Formatted and raw JSON views

- βœ… Responsive layout

- βœ… Real-time processing



## πŸš€ Quick Start (TL;DR)



```powershell

# 1. Install dependencies

pip install -r requirements.txt



# 2. Build data (if needed)

python -m adapters.build_corpora



# 3. Launch UI (choose one)

python app.py              # Gradio (recommended)

streamlit run app_streamlit.py  # Streamlit (alternative)

```



## 🌟 Which UI to Use?



### Use Gradio (`app.py`) if you want:

- Quick setup and deployment

- Clean, minimal interface

- Easy sharing (public links)

- Automatic REST API

- Better for demos and presentations



### Use Streamlit (`app_streamlit.py`) if you want:

- More interactive controls

- Sidebar with settings

- More customization options

- Data-science focused interface



**Recommendation:** Start with **Gradio** - it's simpler and looks very professional!

## πŸ“Š How It Works

```

User Input β†’ Gradio/Streamlit Interface

    ↓

Classifier (classify query as medical/admin/other)

    ↓

If Medical β†’ Retriever (BM25 + Dense + RRF)

    ↓

Optional Reranker (cross-encoder)

    ↓

Display Results (formatted cards + JSON)

```

## πŸŽ“ For Your Presentation

### Demo Flow:
1. **Open the interface** - Show the clean design
2. **Enter a medical query** - e.g., "I have a rash on my hands"
3. **Show classification** - Highlight confidence scores
4. **Display results** - Show retrieved medical documents
5. **Try administrative query** - Show different handling
6. **Toggle settings** - Demonstrate reranker and result count
7. **Show JSON view** - For technical audience

### Key Talking Points:
- "We built a user-friendly web interface using Gradio"
- "The system classifies queries in real-time with confidence scores"
- "For medical queries, it retrieves relevant research from PubMed and Miriad"
- "Uses hybrid search combining BM25 and dense embeddings"
- "Optional reranker for improved accuracy"

## 🎨 Customization Options

### Change Theme/Colors
Edit the CSS in `app.py`:
```python

custom_css = """

.header {

    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

}

"""

```

### Add More Example Queries
Edit the `examples` list in `app.py`:
```python

gr.Examples(

    examples=[

        ["Your custom query here"],

    ],

    inputs=query_input,

)

```

### Change Port
```python

demo.launch(server_port=8080)  # Default is 7860

```

### Enable Public Sharing
```python

demo.launch(share=True)  # Creates 72-hour public link

```

## πŸ”§ Technical Details

### Gradio Version
- Framework: Gradio 4.x
- Features: Blocks API, custom CSS, examples, tabs
- Auto-generates REST API at `/docs`

### Streamlit Version
- Framework: Streamlit
- Features: Sidebar, caching, progress bars, metrics
- More suitable for data exploration

### Integration
- Uses existing classifier and retriever modules
- No changes to core logic
- Models loaded once and cached
- Async processing for better UX

## πŸ“ File Structure

```

health-query-classifier/

β”œβ”€β”€ app.py                  # ← Main Gradio UI

β”œβ”€β”€ app_streamlit.py        # ← Alternative Streamlit UI

β”œβ”€β”€ setup_ui.py             # ← Setup script

β”œβ”€β”€ QUICKSTART.md           # ← Quick start guide

β”œβ”€β”€ UI_README.md            # ← Detailed documentation

β”œβ”€β”€ requirements.txt        # ← Updated with gradio/streamlit

β”œβ”€β”€ classifier/

β”‚   β”œβ”€β”€ infer.py           # Used by UI

β”‚   └── ...

β”œβ”€β”€ retriever/

β”‚   └── ...

└── team/

    β”œβ”€β”€ candidates.py      # Used by UI

    └── ...

```

## πŸ› Common Issues & Solutions

### "Module not found: gradio"
```powershell

pip install gradio

```

### "No corpora files found"
```powershell

python -m adapters.build_corpora

```

### Models take long to load
- This is normal on first run
- Models are cached after initial load
- Consider using smaller models for faster demo

### Port already in use
- Change port in `app.py` (line ~255)
- Or kill the process using that port

## 🌐 Deployment Options

### Local (Current Setup)
- Best for development and demos
- Access via localhost

### Hugging Face Spaces (Free)
- Free hosting for Gradio apps
- Easy to deploy
- Public URL

### Cloud Platforms
- AWS, Google Cloud, Azure
- More control and scalability
- Requires more setup

## πŸ“ˆ Future Enhancements

Potential additions for future development:
- User authentication
- Query history
- Bookmarking results
- Export to PDF
- Multi-language support
- Voice input
- Mobile app
- Analytics dashboard

## πŸ‘₯ Team Contributions

This UI implementation demonstrates:
- Full-stack development skills
- ML model integration
- User experience design
- Modern web frameworks
- Professional documentation

Perfect for showcasing in your group project presentation!

## πŸ“ž Support

For issues or questions:
1. Check `QUICKSTART.md` for setup issues
2. Check `UI_README.md` for feature documentation
3. Review error messages carefully
4. Contact team members

---

## βœ… Ready to Present!

Your medical Q&A bot now has a professional web interface that:
- βœ… Looks modern and clean
- βœ… Is easy to use
- βœ… Demonstrates your ML capabilities
- βœ… Provides clear results
- βœ… Is well-documented
- βœ… Can be easily deployed

**Great work, team!** πŸŽ‰

---

*Created by: Tarak Jha, with contributions from the entire team*
*Team: David Gray β€’ Tarak Jha β€’ Sravani Segireddy β€’ Riley Millikan β€’ Kent R. Spillner*