Spaces:
Sleeping
Sleeping
IDAgents Developer
commited on
Commit
Β·
96e3076
1
Parent(s):
b6b1d23
Fix: Restore complex app with corrected authentication
Browse filesFIXES:
Removed 'show_tips' parameter from hf_config.py (main culprit)
Removed other unsupported Gradio 4.20.0 parameters (height, width, ssl_*, app_kwargs)
Simplified authentication to use only Gradio built-in auth
Removed complex custom auth system that was causing conflicts
Kept all 10 beta testing accounts with existing credentials
Preserved full UI functionality (patient scenarios, chat, etc.)
This should resolve the 'Blocks.launch() got an unexpected keyword argument show_tips' error
while maintaining full app functionality with working authentication.
- app.py +517 -15
- hf_config.py +4 -11
app.py
CHANGED
|
@@ -1,21 +1,523 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
app.py - ID Agents with Fixed Authentication
|
| 3 |
+
-------------------------------------------
|
| 4 |
+
|
| 5 |
+
Main application entry point for the modular AI agent system with working authentication.
|
| 6 |
+
Fixed version that removes problematic parameters causing initialization failures.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
# --- Core Imports ---
|
| 10 |
import gradio as gr
|
| 11 |
+
import json
|
| 12 |
+
import re
|
| 13 |
+
import os
|
| 14 |
+
import asyncio
|
| 15 |
+
import logging
|
| 16 |
+
from typing import Dict, Optional, Any, cast
|
| 17 |
+
|
| 18 |
+
# Try to import OpenAI
|
| 19 |
+
try:
|
| 20 |
+
import openai
|
| 21 |
+
from openai import RateLimitError, APIError, APIConnectionError, OpenAI
|
| 22 |
+
OPENAI_AVAILABLE = True
|
| 23 |
+
print("β
OpenAI client loaded")
|
| 24 |
+
except ImportError as e:
|
| 25 |
+
print(f"β οΈ OpenAI not available: {e}")
|
| 26 |
+
OPENAI_AVAILABLE = False
|
| 27 |
+
|
| 28 |
+
# Try to import core modules
|
| 29 |
+
try:
|
| 30 |
+
from orchestrator import AIOrchestrator
|
| 31 |
+
from llm_connector import LLMConnector
|
| 32 |
+
from rag import RAGRetriever
|
| 33 |
+
CORE_MODULES_AVAILABLE = True
|
| 34 |
+
print("β
Core modules loaded")
|
| 35 |
+
except ImportError as e:
|
| 36 |
+
print(f"β οΈ Core modules not available: {e}")
|
| 37 |
+
CORE_MODULES_AVAILABLE = False
|
| 38 |
+
|
| 39 |
+
# Set up logging
|
| 40 |
+
logging.basicConfig(level=logging.INFO)
|
| 41 |
+
logger = logging.getLogger(__name__)
|
| 42 |
|
| 43 |
+
# --- Global Variables ---
|
| 44 |
+
current_llm_connector = None
|
| 45 |
+
current_orchestrator = None
|
| 46 |
+
current_rag_retriever = None
|
| 47 |
+
|
| 48 |
+
# --- Helper Functions ---
|
| 49 |
+
|
| 50 |
+
def initialize_components():
|
| 51 |
+
"""Initialize core components if available"""
|
| 52 |
+
global current_llm_connector, current_orchestrator, current_rag_retriever
|
| 53 |
+
|
| 54 |
+
if not CORE_MODULES_AVAILABLE:
|
| 55 |
+
return False
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
# Initialize LLM Connector
|
| 59 |
+
current_llm_connector = LLMConnector()
|
| 60 |
+
|
| 61 |
+
# Initialize RAG Retriever
|
| 62 |
+
current_rag_retriever = RAGRetriever()
|
| 63 |
+
|
| 64 |
+
# Initialize Orchestrator
|
| 65 |
+
current_orchestrator = AIOrchestrator(current_llm_connector, current_rag_retriever)
|
| 66 |
+
|
| 67 |
+
print("β
All components initialized successfully")
|
| 68 |
+
return True
|
| 69 |
+
except Exception as e:
|
| 70 |
+
print(f"β Component initialization failed: {e}")
|
| 71 |
+
return False
|
| 72 |
+
|
| 73 |
+
def safe_chat_response(message: str, history: list) -> tuple:
|
| 74 |
+
"""Safe chat response with fallback"""
|
| 75 |
+
if not CORE_MODULES_AVAILABLE or not current_orchestrator:
|
| 76 |
+
response = """
|
| 77 |
+
π§ **System Status**: Core modules are not fully available.
|
| 78 |
+
|
| 79 |
+
This is a demo version of ID Agents. In the full version, you would have access to:
|
| 80 |
+
|
| 81 |
+
β’ **AI-Powered Clinical Assistance**: Advanced infectious disease consultation
|
| 82 |
+
β’ **Multi-Agent Orchestration**: Coordinated responses from specialized agents
|
| 83 |
+
β’ **Knowledge Base Integration**: Access to medical literature and guidelines
|
| 84 |
+
β’ **Patient Scenario Analysis**: Context-aware clinical decision support
|
| 85 |
+
|
| 86 |
+
**Authentication Working**: You are successfully logged in!
|
| 87 |
+
**Current Status**: Demo mode with limited functionality
|
| 88 |
+
|
| 89 |
+
Please contact the administrator for full access.
|
| 90 |
+
"""
|
| 91 |
+
return response, history + [[message, response]]
|
| 92 |
+
|
| 93 |
+
try:
|
| 94 |
+
# Get response from orchestrator
|
| 95 |
+
response = current_orchestrator.process_query(message)
|
| 96 |
+
|
| 97 |
+
# Update history
|
| 98 |
+
updated_history = history + [[message, response]]
|
| 99 |
+
|
| 100 |
+
return response, updated_history
|
| 101 |
+
|
| 102 |
+
except Exception as e:
|
| 103 |
+
error_response = f"β Error processing your request: {str(e)}"
|
| 104 |
+
return error_response, history + [[message, error_response]]
|
| 105 |
+
|
| 106 |
+
def convert_messages_for_gradio(messages):
|
| 107 |
+
"""Convert messages to Gradio 4.20.0 format"""
|
| 108 |
+
if not messages:
|
| 109 |
+
return []
|
| 110 |
+
|
| 111 |
+
converted = []
|
| 112 |
+
for msg in messages:
|
| 113 |
+
if isinstance(msg, dict) and 'role' in msg and 'content' in msg:
|
| 114 |
+
if msg['role'] == 'user':
|
| 115 |
+
converted.append([msg['content'], None])
|
| 116 |
+
elif msg['role'] == 'assistant' and converted:
|
| 117 |
+
converted[-1][1] = msg['content']
|
| 118 |
+
elif msg['role'] == 'assistant':
|
| 119 |
+
converted.append([None, msg['content']])
|
| 120 |
+
elif isinstance(msg, list) and len(msg) == 2:
|
| 121 |
+
converted.append(msg)
|
| 122 |
+
|
| 123 |
+
return converted
|
| 124 |
+
|
| 125 |
+
# Patient loading functions (simplified)
|
| 126 |
+
def load_patient_1():
|
| 127 |
+
patient_data = {
|
| 128 |
+
"name": "Maria Santos",
|
| 129 |
+
"age": 67,
|
| 130 |
+
"gender": "Female",
|
| 131 |
+
"chief_complaint": "Fever and shortness of breath",
|
| 132 |
+
"history": "3 days of progressive fever (up to 101.8Β°F), productive cough with yellow sputum, and increasing shortness of breath...",
|
| 133 |
+
"vitals": "Temp: 101.8Β°F, HR: 110, BP: 145/85, RR: 22, O2 Sat: 89% on room air",
|
| 134 |
+
"presentation": "Elderly female with fever, productive cough, and hypoxemia concerning for pneumonia"
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
context_message = f"""
|
| 138 |
+
π₯ **Patient Case Loaded: {patient_data['name']}**
|
| 139 |
+
|
| 140 |
+
**Demographics:** {patient_data['age']}-year-old {patient_data['gender']}
|
| 141 |
+
**Chief Complaint:** {patient_data['chief_complaint']}
|
| 142 |
+
**Current Vitals:** {patient_data['vitals']}
|
| 143 |
+
|
| 144 |
+
**Clinical Presentation:** {patient_data['presentation']}
|
| 145 |
+
|
| 146 |
+
How can I assist with this case?
|
| 147 |
+
"""
|
| 148 |
+
|
| 149 |
+
history = [[f"Load patient case: {patient_data['name']}", context_message]]
|
| 150 |
+
return convert_messages_for_gradio([]), history
|
| 151 |
+
|
| 152 |
+
def load_patient_2():
|
| 153 |
+
patient_data = {
|
| 154 |
+
"name": "James Wilson",
|
| 155 |
+
"age": 34,
|
| 156 |
+
"gender": "Male",
|
| 157 |
+
"chief_complaint": "Painful urination and fever",
|
| 158 |
+
"presentation": "Young male with UTI symptoms and systemic signs of infection"
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
context_message = f"""
|
| 162 |
+
π₯ **Patient Case Loaded: {patient_data['name']}**
|
| 163 |
+
|
| 164 |
+
**Demographics:** {patient_data['age']}-year-old {patient_data['gender']}
|
| 165 |
+
**Chief Complaint:** {patient_data['chief_complaint']}
|
| 166 |
+
|
| 167 |
+
**Clinical Presentation:** {patient_data['presentation']}
|
| 168 |
+
|
| 169 |
+
How can I assist with this case?
|
| 170 |
+
"""
|
| 171 |
+
|
| 172 |
+
history = [[f"Load patient case: {patient_data['name']}", context_message]]
|
| 173 |
+
return convert_messages_for_gradio([]), history
|
| 174 |
+
|
| 175 |
+
def load_patient_3():
|
| 176 |
+
patient_data = {
|
| 177 |
+
"name": "Sarah Chen",
|
| 178 |
+
"age": 28,
|
| 179 |
+
"gender": "Female",
|
| 180 |
+
"chief_complaint": "Skin rash and joint pain",
|
| 181 |
+
"presentation": "Young female with systemic symptoms and dermatologic findings"
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
context_message = f"""
|
| 185 |
+
π₯ **Patient Case Loaded: {patient_data['name']}**
|
| 186 |
+
|
| 187 |
+
**Demographics:** {patient_data['age']}-year-old {patient_data['gender']}
|
| 188 |
+
**Chief Complaint:** {patient_data['chief_complaint']}
|
| 189 |
+
|
| 190 |
+
**Clinical Presentation:** {patient_data['presentation']}
|
| 191 |
+
|
| 192 |
+
How can I assist with this case?
|
| 193 |
+
"""
|
| 194 |
+
|
| 195 |
+
history = [[f"Load patient case: {patient_data['name']}", context_message]]
|
| 196 |
+
return convert_messages_for_gradio([]), history
|
| 197 |
|
| 198 |
+
def load_patient_4():
|
| 199 |
+
patient_data = {
|
| 200 |
+
"name": "Robert Martinez",
|
| 201 |
+
"age": 45,
|
| 202 |
+
"gender": "Male",
|
| 203 |
+
"chief_complaint": "Persistent cough and weight loss",
|
| 204 |
+
"presentation": "Middle-aged male with chronic respiratory symptoms and constitutional signs"
|
| 205 |
+
}
|
| 206 |
|
| 207 |
+
context_message = f"""
|
| 208 |
+
π₯ **Patient Case Loaded: {patient_data['name']}**
|
| 209 |
+
|
| 210 |
+
**Demographics:** {patient_data['age']}-year-old {patient_data['gender']}
|
| 211 |
+
**Chief Complaint:** {patient_data['chief_complaint']}
|
| 212 |
+
|
| 213 |
+
**Clinical Presentation:** {patient_data['presentation']}
|
| 214 |
+
|
| 215 |
+
How can I assist with this case?
|
| 216 |
+
"""
|
| 217 |
+
|
| 218 |
+
history = [[f"Load patient case: {patient_data['name']}", context_message]]
|
| 219 |
+
return convert_messages_for_gradio([]), history
|
| 220 |
+
|
| 221 |
+
def load_patient_5():
|
| 222 |
+
patient_data = {
|
| 223 |
+
"name": "Emma Thompson",
|
| 224 |
+
"age": 19,
|
| 225 |
+
"gender": "Female",
|
| 226 |
+
"chief_complaint": "Headache and neck stiffness",
|
| 227 |
+
"presentation": "Young female with meningeal signs requiring urgent evaluation"
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
context_message = f"""
|
| 231 |
+
π₯ **Patient Case Loaded: {patient_data['name']}**
|
| 232 |
+
|
| 233 |
+
**Demographics:** {patient_data['age']}-year-old {patient_data['gender']}
|
| 234 |
+
**Chief Complaint:** {patient_data['chief_complaint']}
|
| 235 |
+
|
| 236 |
+
**Clinical Presentation:** {patient_data['presentation']}
|
| 237 |
+
|
| 238 |
+
How can I assist with this case?
|
| 239 |
+
"""
|
| 240 |
+
|
| 241 |
+
history = [[f"Load patient case: {patient_data['name']}", context_message]]
|
| 242 |
+
return convert_messages_for_gradio([]), history
|
| 243 |
+
|
| 244 |
+
def load_patient_6():
|
| 245 |
+
patient_data = {
|
| 246 |
+
"name": "Michael Brown",
|
| 247 |
+
"age": 72,
|
| 248 |
+
"gender": "Male",
|
| 249 |
+
"chief_complaint": "Abdominal pain and diarrhea",
|
| 250 |
+
"presentation": "Elderly male with GI symptoms and potential infectious etiology"
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
context_message = f"""
|
| 254 |
+
π₯ **Patient Case Loaded: {patient_data['name']}**
|
| 255 |
+
|
| 256 |
+
**Demographics:** {patient_data['age']}-year-old {patient_data['gender']}
|
| 257 |
+
**Chief Complaint:** {patient_data['chief_complaint']}
|
| 258 |
+
|
| 259 |
+
**Clinical Presentation:** {patient_data['presentation']}
|
| 260 |
+
|
| 261 |
+
How can I assist with this case?
|
| 262 |
+
"""
|
| 263 |
+
|
| 264 |
+
history = [[f"Load patient case: {patient_data['name']}", context_message]]
|
| 265 |
+
return convert_messages_for_gradio([]), history
|
| 266 |
+
|
| 267 |
+
# --- Main UI Builder ---
|
| 268 |
+
|
| 269 |
+
def build_ui():
|
| 270 |
+
"""Build the main Gradio interface"""
|
| 271 |
+
|
| 272 |
+
# Initialize components on startup
|
| 273 |
+
initialize_components()
|
| 274 |
+
|
| 275 |
+
# Custom CSS
|
| 276 |
+
css = """
|
| 277 |
+
:root {
|
| 278 |
+
--id-primary: #1e40af;
|
| 279 |
+
--id-secondary: #3b82f6;
|
| 280 |
+
--id-accent: #06d6a0;
|
| 281 |
+
--id-success: #059669;
|
| 282 |
+
--id-warning: #d97706;
|
| 283 |
+
--id-error: #dc2626;
|
| 284 |
+
--id-bg: #f8fafc;
|
| 285 |
+
--id-surface: #ffffff;
|
| 286 |
+
--id-text: #1e293b;
|
| 287 |
+
--id-text-muted: #64748b;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
.gradio-container {
|
| 291 |
+
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
|
| 292 |
+
min-height: 100vh;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
.id-header {
|
| 296 |
+
background: linear-gradient(90deg, var(--id-primary), var(--id-secondary));
|
| 297 |
+
color: white;
|
| 298 |
+
padding: 1.5rem;
|
| 299 |
+
border-radius: 12px;
|
| 300 |
+
margin-bottom: 1.5rem;
|
| 301 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
.id-card {
|
| 305 |
+
background: var(--id-surface);
|
| 306 |
+
border-radius: 12px;
|
| 307 |
+
padding: 1.5rem;
|
| 308 |
+
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
|
| 309 |
+
border: 1px solid #e2e8f0;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
.patient-card {
|
| 313 |
+
background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
|
| 314 |
+
border: 2px solid var(--id-secondary);
|
| 315 |
+
border-radius: 8px;
|
| 316 |
+
padding: 1rem;
|
| 317 |
+
margin: 0.5rem 0;
|
| 318 |
+
cursor: pointer;
|
| 319 |
+
transition: all 0.2s ease;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
.patient-card:hover {
|
| 323 |
+
transform: translateY(-2px);
|
| 324 |
+
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.chat-container {
|
| 328 |
+
background: var(--id-surface);
|
| 329 |
+
border-radius: 12px;
|
| 330 |
+
border: 1px solid #e2e8f0;
|
| 331 |
+
}
|
| 332 |
+
"""
|
| 333 |
+
|
| 334 |
+
with gr.Blocks(title="π¦ ID Agents - Infectious Disease AI", css=css, theme=gr.themes.Soft()) as app:
|
| 335 |
+
|
| 336 |
+
# Header
|
| 337 |
+
gr.HTML("""
|
| 338 |
+
<div class="id-header">
|
| 339 |
+
<h1 style="margin: 0; display: flex; align-items: center; gap: 12px;">
|
| 340 |
+
π¦ <span>ID Agents</span>
|
| 341 |
+
<span style="font-size: 0.7em; background: rgba(255,255,255,0.2); padding: 4px 8px; border-radius: 6px;">BETA</span>
|
| 342 |
+
</h1>
|
| 343 |
+
<p style="margin: 8px 0 0 0; opacity: 0.9;">AI-Powered Infectious Disease Clinical Decision Support</p>
|
| 344 |
+
</div>
|
| 345 |
+
""")
|
| 346 |
+
|
| 347 |
+
with gr.Row():
|
| 348 |
+
# Left column - Chat interface
|
| 349 |
+
with gr.Column(scale=7):
|
| 350 |
+
with gr.Group(elem_classes="id-card"):
|
| 351 |
+
gr.Markdown("### π¬ Clinical Consultation Chat")
|
| 352 |
+
|
| 353 |
+
chatbot = gr.Chatbot(
|
| 354 |
+
value=[],
|
| 355 |
+
height=400,
|
| 356 |
+
elem_classes="chat-container",
|
| 357 |
+
show_label=False,
|
| 358 |
+
avatar_images=(None, "π¦ ")
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
with gr.Row():
|
| 362 |
+
msg_input = gr.Textbox(
|
| 363 |
+
placeholder="Ask about infectious diseases, patient cases, or clinical guidelines...",
|
| 364 |
+
show_label=False,
|
| 365 |
+
scale=4
|
| 366 |
+
)
|
| 367 |
+
submit_btn = gr.Button("Send", variant="primary", scale=1)
|
| 368 |
+
|
| 369 |
+
gr.Examples(
|
| 370 |
+
examples=[
|
| 371 |
+
"What are the current guidelines for treating MRSA pneumonia?",
|
| 372 |
+
"Help me interpret these blood culture results",
|
| 373 |
+
"What empirical antibiotics should I start for severe sepsis?",
|
| 374 |
+
"Explain the mechanism of carbapenem resistance",
|
| 375 |
+
"What's the latest on COVID-19 treatment protocols?"
|
| 376 |
+
],
|
| 377 |
+
inputs=msg_input,
|
| 378 |
+
label="π‘ Example Queries"
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
# Right column - Tools and patient scenarios
|
| 382 |
+
with gr.Column(scale=3):
|
| 383 |
+
with gr.Group(elem_classes="id-card"):
|
| 384 |
+
gr.Markdown("### π₯ Patient Scenarios")
|
| 385 |
+
gr.Markdown("*Click to load a clinical case*")
|
| 386 |
+
|
| 387 |
+
# Patient scenario buttons
|
| 388 |
+
with gr.Column():
|
| 389 |
+
patient1_btn = gr.Button("π΅ Maria S. - Pneumonia (67F)", elem_classes="patient-card")
|
| 390 |
+
patient2_btn = gr.Button("π¨ James W. - UTI/Sepsis (34M)", elem_classes="patient-card")
|
| 391 |
+
patient3_btn = gr.Button("π© Sarah C. - Rash/Arthritis (28F)", elem_classes="patient-card")
|
| 392 |
+
patient4_btn = gr.Button("π¨ Robert M. - Chronic Cough (45M)", elem_classes="patient-card")
|
| 393 |
+
patient5_btn = gr.Button("π© Emma T. - Meningitis (19F)", elem_classes="patient-card")
|
| 394 |
+
patient6_btn = gr.Button("π΄ Michael B. - GI Infection (72M)", elem_classes="patient-card")
|
| 395 |
+
|
| 396 |
+
with gr.Group(elem_classes="id-card"):
|
| 397 |
+
gr.Markdown("### π§ System Status")
|
| 398 |
+
|
| 399 |
+
if CORE_MODULES_AVAILABLE:
|
| 400 |
+
status_msg = "β
**Core modules loaded**\nβ
**AI orchestrator active**\nβ
**Knowledge base ready**"
|
| 401 |
+
else:
|
| 402 |
+
status_msg = "β οΈ **Limited functionality**\nπ§ **Core modules unavailable**\nπ‘ **Demo mode active**"
|
| 403 |
+
|
| 404 |
+
gr.Markdown(status_msg)
|
| 405 |
+
|
| 406 |
+
# Event handlers
|
| 407 |
+
def handle_submit(message, history):
|
| 408 |
+
if not message.strip():
|
| 409 |
+
return "", history
|
| 410 |
+
|
| 411 |
+
response, updated_history = safe_chat_response(message, history)
|
| 412 |
+
return "", updated_history
|
| 413 |
+
|
| 414 |
+
# Wire up the chat interface
|
| 415 |
+
submit_btn.click(
|
| 416 |
+
fn=handle_submit,
|
| 417 |
+
inputs=[msg_input, chatbot],
|
| 418 |
+
outputs=[msg_input, chatbot]
|
| 419 |
+
)
|
| 420 |
+
|
| 421 |
+
msg_input.submit(
|
| 422 |
+
fn=handle_submit,
|
| 423 |
+
inputs=[msg_input, chatbot],
|
| 424 |
+
outputs=[msg_input, chatbot]
|
| 425 |
+
)
|
| 426 |
+
|
| 427 |
+
# Wire up patient loading buttons
|
| 428 |
+
patient1_btn.click(fn=load_patient_1, outputs=[msg_input, chatbot])
|
| 429 |
+
patient2_btn.click(fn=load_patient_2, outputs=[msg_input, chatbot])
|
| 430 |
+
patient3_btn.click(fn=load_patient_3, outputs=[msg_input, chatbot])
|
| 431 |
+
patient4_btn.click(fn=load_patient_4, outputs=[msg_input, chatbot])
|
| 432 |
+
patient5_btn.click(fn=load_patient_5, outputs=[msg_input, chatbot])
|
| 433 |
+
patient6_btn.click(fn=load_patient_6, outputs=[msg_input, chatbot])
|
| 434 |
+
|
| 435 |
+
return app
|
| 436 |
+
|
| 437 |
+
# --- Main Application Entry Point ---
|
| 438 |
|
| 439 |
if __name__ == "__main__":
|
| 440 |
+
try:
|
| 441 |
+
print("π Launching ID Agents with Fixed Authentication...")
|
| 442 |
+
|
| 443 |
+
# Create main app
|
| 444 |
+
app = build_ui()
|
| 445 |
+
|
| 446 |
+
# Authentication credentials (Gradio built-in auth)
|
| 447 |
+
auth_credentials = [
|
| 448 |
+
("dr_smith", "idweek2025"),
|
| 449 |
+
("id_fellow", "hello"),
|
| 450 |
+
("pharmacist", "stewardship"),
|
| 451 |
+
("ipc_nurse", "infection"),
|
| 452 |
+
("researcher", "research"),
|
| 453 |
+
("educator", "education"),
|
| 454 |
+
("student", "learning"),
|
| 455 |
+
("admin", "idagents2025"),
|
| 456 |
+
("guest1", "guest123"),
|
| 457 |
+
("guest2", "guest456")
|
| 458 |
+
]
|
| 459 |
+
|
| 460 |
+
auth_message = """
|
| 461 |
+
π¦ **ID Agents Beta Testing Access**
|
| 462 |
+
|
| 463 |
+
Welcome to the ID Agents beta testing environment!
|
| 464 |
+
|
| 465 |
+
**Available Test Accounts:**
|
| 466 |
+
β’ **dr_smith** / idweek2025 (ID Physician)
|
| 467 |
+
β’ **id_fellow** / hello (ID Fellow)
|
| 468 |
+
β’ **pharmacist** / stewardship (Clinical Pharmacist)
|
| 469 |
+
β’ **ipc_nurse** / infection (IPC Coordinator)
|
| 470 |
+
β’ **researcher** / research (Clinical Researcher)
|
| 471 |
+
β’ **educator** / education (Medical Educator)
|
| 472 |
+
β’ **student** / learning (Medical Student - Limited Access)
|
| 473 |
+
β’ **admin** / idagents2025 (Administrator)
|
| 474 |
+
β’ **guest1** / guest123 (Guest Access - Limited)
|
| 475 |
+
β’ **guest2** / guest456 (Guest Access - Limited)
|
| 476 |
+
|
| 477 |
+
Please use your assigned credentials to access the application.
|
| 478 |
+
Built with β€οΈ for ID Week 2025 β Empowering Infectious Diseases Innovation
|
| 479 |
+
"""
|
| 480 |
+
|
| 481 |
+
# Check if running on Hugging Face Spaces (with fixed config)
|
| 482 |
+
try:
|
| 483 |
+
from hf_config import configure_hf_environment, get_hf_launch_config
|
| 484 |
+
if configure_hf_environment():
|
| 485 |
+
# Use FIXED HF Spaces configuration with authentication
|
| 486 |
+
launch_config = get_hf_launch_config()
|
| 487 |
+
launch_config["auth"] = auth_credentials
|
| 488 |
+
launch_config["auth_message"] = auth_message
|
| 489 |
+
print("π Authentication enabled for HF Spaces deployment (FIXED)")
|
| 490 |
+
else:
|
| 491 |
+
# Local development with authentication for testing
|
| 492 |
+
launch_config = {
|
| 493 |
+
"auth": auth_credentials,
|
| 494 |
+
"auth_message": auth_message,
|
| 495 |
+
"share": False,
|
| 496 |
+
"server_name": "127.0.0.1",
|
| 497 |
+
"server_port": 7860,
|
| 498 |
+
"show_error": True
|
| 499 |
+
}
|
| 500 |
+
print("π Authentication enabled for local testing")
|
| 501 |
+
except ImportError:
|
| 502 |
+
# Fallback configuration with authentication
|
| 503 |
+
launch_config = {
|
| 504 |
+
"auth": auth_credentials,
|
| 505 |
+
"auth_message": auth_message,
|
| 506 |
+
"share": False,
|
| 507 |
+
"server_name": "127.0.0.1",
|
| 508 |
+
"server_port": 7860,
|
| 509 |
+
"show_error": True
|
| 510 |
+
}
|
| 511 |
+
print("π Authentication enabled with fallback configuration")
|
| 512 |
+
|
| 513 |
+
print("π Available beta test accounts:")
|
| 514 |
+
for username, password in auth_credentials:
|
| 515 |
+
print(f" β’ {username} / {password}")
|
| 516 |
+
|
| 517 |
+
app.launch(**launch_config)
|
| 518 |
+
|
| 519 |
+
except Exception as e:
|
| 520 |
+
print(f"β Failed to launch ID Agents: {e}")
|
| 521 |
+
print("π‘ Check your API keys and environment configuration")
|
| 522 |
+
import traceback
|
| 523 |
+
traceback.print_exc()
|
hf_config.py
CHANGED
|
@@ -31,23 +31,16 @@ def configure_hf_environment():
|
|
| 31 |
def get_hf_launch_config():
|
| 32 |
"""
|
| 33 |
Get launch configuration for Hugging Face Spaces
|
|
|
|
| 34 |
"""
|
| 35 |
config = {
|
| 36 |
"server_name": "0.0.0.0",
|
| 37 |
"server_port": 7860,
|
| 38 |
"share": False,
|
| 39 |
"show_error": True,
|
| 40 |
-
"quiet": False
|
| 41 |
-
|
| 42 |
-
"height": 500,
|
| 43 |
-
"width": "100%",
|
| 44 |
-
"favicon_path": None,
|
| 45 |
-
"ssl_keyfile": None,
|
| 46 |
-
"ssl_certfile": None,
|
| 47 |
-
"ssl_keyfile_password": None,
|
| 48 |
-
"ssl_verify": True,
|
| 49 |
-
"app_kwargs": {}
|
| 50 |
}
|
| 51 |
|
| 52 |
-
print("βοΈ Using Hugging Face Spaces launch configuration")
|
| 53 |
return config
|
|
|
|
| 31 |
def get_hf_launch_config():
|
| 32 |
"""
|
| 33 |
Get launch configuration for Hugging Face Spaces
|
| 34 |
+
Compatible with Gradio 4.20.0 - removed unsupported parameters
|
| 35 |
"""
|
| 36 |
config = {
|
| 37 |
"server_name": "0.0.0.0",
|
| 38 |
"server_port": 7860,
|
| 39 |
"share": False,
|
| 40 |
"show_error": True,
|
| 41 |
+
"quiet": False
|
| 42 |
+
# Removed: show_tips, height, width, ssl_*, app_kwargs - not supported in 4.20.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
+
print("βοΈ Using Hugging Face Spaces launch configuration (Gradio 4.20.0 compatible)")
|
| 46 |
return config
|