Spaces:
Running
Running
Delete src/ui_components.py
Browse files- src/ui_components.py +0 -349
src/ui_components.py
DELETED
|
@@ -1,349 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import logging
|
| 3 |
-
|
| 4 |
-
class UIComponents:
|
| 5 |
-
"""UI components and styling for SmartHeal application"""
|
| 6 |
-
|
| 7 |
-
def __init__(self):
|
| 8 |
-
"""Initialize UI components"""
|
| 9 |
-
self.theme = gr.themes.Soft()
|
| 10 |
-
self.custom_css = self._load_custom_css()
|
| 11 |
-
|
| 12 |
-
def _load_custom_css(self):
|
| 13 |
-
"""Load custom CSS for the application"""
|
| 14 |
-
return """
|
| 15 |
-
/* Main Application Styling */
|
| 16 |
-
.main-header {
|
| 17 |
-
text-align: center;
|
| 18 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 19 |
-
color: white;
|
| 20 |
-
padding: 2rem;
|
| 21 |
-
border-radius: 10px;
|
| 22 |
-
margin-bottom: 2rem;
|
| 23 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
.main-header h1 {
|
| 27 |
-
margin: 0;
|
| 28 |
-
font-size: 2.5rem;
|
| 29 |
-
font-weight: bold;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
.main-header p {
|
| 33 |
-
margin: 0.5rem 0 0 0;
|
| 34 |
-
font-size: 1.1rem;
|
| 35 |
-
opacity: 0.9;
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
/* Section Headers */
|
| 39 |
-
.section-header {
|
| 40 |
-
background-color: #f8f9fa;
|
| 41 |
-
padding: 1rem;
|
| 42 |
-
border-radius: 8px;
|
| 43 |
-
border-left: 4px solid #007bff;
|
| 44 |
-
margin: 1rem 0;
|
| 45 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
.section-header h2 {
|
| 49 |
-
margin: 0;
|
| 50 |
-
color: #495057;
|
| 51 |
-
font-size: 1.3rem;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
.section-header h3 {
|
| 55 |
-
margin: 0;
|
| 56 |
-
color: #6c757d;
|
| 57 |
-
font-size: 1.1rem;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/* Result Boxes */
|
| 61 |
-
.result-box {
|
| 62 |
-
background-color: #e7f3ff;
|
| 63 |
-
border: 1px solid #b3d9ff;
|
| 64 |
-
border-radius: 8px;
|
| 65 |
-
padding: 1rem;
|
| 66 |
-
margin: 1rem 0;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
.success-box {
|
| 70 |
-
background-color: #d4edda;
|
| 71 |
-
border: 1px solid #c3e6cb;
|
| 72 |
-
border-radius: 8px;
|
| 73 |
-
padding: 1rem;
|
| 74 |
-
margin: 1rem 0;
|
| 75 |
-
color: #155724;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
.warning-box {
|
| 79 |
-
background-color: #fff3cd;
|
| 80 |
-
border: 1px solid #ffeaa7;
|
| 81 |
-
border-radius: 8px;
|
| 82 |
-
padding: 1rem;
|
| 83 |
-
margin: 1rem 0;
|
| 84 |
-
color: #856404;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
.error-box {
|
| 88 |
-
background-color: #ffe7e7;
|
| 89 |
-
border: 1px solid #ffb3b3;
|
| 90 |
-
border-radius: 8px;
|
| 91 |
-
padding: 1rem;
|
| 92 |
-
margin: 1rem 0;
|
| 93 |
-
color: #721c24;
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/* Form Styling */
|
| 97 |
-
.form-group {
|
| 98 |
-
margin-bottom: 1rem;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
.required-field::after {
|
| 102 |
-
content: " *";
|
| 103 |
-
color: #dc3545;
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
/* Button Styling */
|
| 107 |
-
.primary-button {
|
| 108 |
-
background: linear-gradient(45deg, #007bff, #0056b3);
|
| 109 |
-
color: white;
|
| 110 |
-
border: none;
|
| 111 |
-
padding: 0.75rem 1.5rem;
|
| 112 |
-
border-radius: 5px;
|
| 113 |
-
font-weight: bold;
|
| 114 |
-
transition: all 0.3s ease;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
.primary-button:hover {
|
| 118 |
-
background: linear-gradient(45deg, #0056b3, #004085);
|
| 119 |
-
transform: translateY(-1px);
|
| 120 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
.secondary-button {
|
| 124 |
-
background: #6c757d;
|
| 125 |
-
color: white;
|
| 126 |
-
border: none;
|
| 127 |
-
padding: 0.5rem 1rem;
|
| 128 |
-
border-radius: 5px;
|
| 129 |
-
transition: all 0.3s ease;
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
.secondary-button:hover {
|
| 133 |
-
background: #545b62;
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
/* Image Upload Styling */
|
| 137 |
-
.image-upload {
|
| 138 |
-
border: 2px dashed #007bff;
|
| 139 |
-
border-radius: 8px;
|
| 140 |
-
padding: 2rem;
|
| 141 |
-
text-align: center;
|
| 142 |
-
transition: all 0.3s ease;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
.image-upload:hover {
|
| 146 |
-
border-color: #0056b3;
|
| 147 |
-
background-color: #f8f9fa;
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
/* Analysis Results */
|
| 151 |
-
.analysis-container {
|
| 152 |
-
background: white;
|
| 153 |
-
border-radius: 10px;
|
| 154 |
-
padding: 1.5rem;
|
| 155 |
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 156 |
-
margin: 1rem 0;
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
.risk-level-low {
|
| 160 |
-
background-color: #d4edda;
|
| 161 |
-
border-left: 4px solid #28a745;
|
| 162 |
-
padding: 0.5rem;
|
| 163 |
-
border-radius: 4px;
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
.risk-level-moderate {
|
| 167 |
-
background-color: #fff3cd;
|
| 168 |
-
border-left: 4px solid #ffc107;
|
| 169 |
-
padding: 0.5rem;
|
| 170 |
-
border-radius: 4px;
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
.risk-level-high {
|
| 174 |
-
background-color: #f8d7da;
|
| 175 |
-
border-left: 4px solid #dc3545;
|
| 176 |
-
padding: 0.5rem;
|
| 177 |
-
border-radius: 4px;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
/* History Styling */
|
| 181 |
-
.history-item {
|
| 182 |
-
background: white;
|
| 183 |
-
border: 1px solid #dee2e6;
|
| 184 |
-
border-radius: 8px;
|
| 185 |
-
padding: 1rem;
|
| 186 |
-
margin: 0.5rem 0;
|
| 187 |
-
transition: all 0.3s ease;
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
-
.history-item:hover {
|
| 191 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
| 192 |
-
transform: translateY(-1px);
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
/* Responsive Design */
|
| 196 |
-
@media (max-width: 768px) {
|
| 197 |
-
.main-header h1 {
|
| 198 |
-
font-size: 2rem;
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
.main-header p {
|
| 202 |
-
font-size: 1rem;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
.primary-button, .secondary-button {
|
| 206 |
-
width: 100%;
|
| 207 |
-
margin: 0.25rem 0;
|
| 208 |
-
}
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
/* Tab Styling */
|
| 212 |
-
.tab-nav {
|
| 213 |
-
background-color: #f8f9fa;
|
| 214 |
-
border-bottom: 1px solid #dee2e6;
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
.tab-content {
|
| 218 |
-
padding: 1.5rem;
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
/* Footer */
|
| 222 |
-
.footer {
|
| 223 |
-
text-align: center;
|
| 224 |
-
padding: 2rem;
|
| 225 |
-
color: #6c757d;
|
| 226 |
-
border-top: 1px solid #dee2e6;
|
| 227 |
-
margin-top: 2rem;
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/* Loading Animation */
|
| 231 |
-
.loading {
|
| 232 |
-
display: inline-block;
|
| 233 |
-
width: 20px;
|
| 234 |
-
height: 20px;
|
| 235 |
-
border: 3px solid #f3f3f3;
|
| 236 |
-
border-top: 3px solid #007bff;
|
| 237 |
-
border-radius: 50%;
|
| 238 |
-
animation: spin 1s linear infinite;
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
@keyframes spin {
|
| 242 |
-
0% { transform: rotate(0deg); }
|
| 243 |
-
100% { transform: rotate(360deg); }
|
| 244 |
-
}
|
| 245 |
-
|
| 246 |
-
/* Medical Icons */
|
| 247 |
-
.medical-icon {
|
| 248 |
-
color: #007bff;
|
| 249 |
-
margin-right: 0.5rem;
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
/* Status Indicators */
|
| 253 |
-
.status-online {
|
| 254 |
-
color: #28a745;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
.status-offline {
|
| 258 |
-
color: #dc3545;
|
| 259 |
-
}
|
| 260 |
-
|
| 261 |
-
.status-warning {
|
| 262 |
-
color: #ffc107;
|
| 263 |
-
}
|
| 264 |
-
"""
|
| 265 |
-
|
| 266 |
-
def create_header(self, title="SmartHeal - AI Wound Analysis", subtitle="Advanced Medical Imaging Analysis for Healthcare Professionals"):
|
| 267 |
-
"""Create application header"""
|
| 268 |
-
return gr.HTML(f"""
|
| 269 |
-
<div class="main-header">
|
| 270 |
-
<h1>🏥 {title}</h1>
|
| 271 |
-
<p>{subtitle}</p>
|
| 272 |
-
</div>
|
| 273 |
-
""")
|
| 274 |
-
|
| 275 |
-
def create_section_header(self, title, icon=""):
|
| 276 |
-
"""Create section header with optional icon"""
|
| 277 |
-
return gr.HTML(f"""
|
| 278 |
-
<div class="section-header">
|
| 279 |
-
<h2>{icon} {title}</h2>
|
| 280 |
-
</div>
|
| 281 |
-
""")
|
| 282 |
-
|
| 283 |
-
def create_subsection_header(self, title):
|
| 284 |
-
"""Create subsection header"""
|
| 285 |
-
return gr.HTML(f"""
|
| 286 |
-
<div class="section-header">
|
| 287 |
-
<h3>{title}</h3>
|
| 288 |
-
</div>
|
| 289 |
-
""")
|
| 290 |
-
|
| 291 |
-
def create_result_box(self, content, box_type="info"):
|
| 292 |
-
"""Create styled result box"""
|
| 293 |
-
css_class = {
|
| 294 |
-
"info": "result-box",
|
| 295 |
-
"success": "success-box",
|
| 296 |
-
"warning": "warning-box",
|
| 297 |
-
"error": "error-box"
|
| 298 |
-
}.get(box_type, "result-box")
|
| 299 |
-
|
| 300 |
-
return gr.HTML(f"""
|
| 301 |
-
<div class="{css_class}">
|
| 302 |
-
{content}
|
| 303 |
-
</div>
|
| 304 |
-
""")
|
| 305 |
-
|
| 306 |
-
def create_footer(self):
|
| 307 |
-
"""Create application footer"""
|
| 308 |
-
return gr.HTML("""
|
| 309 |
-
<div class="footer">
|
| 310 |
-
<p><strong>SmartHeal AI Wound Analysis System</strong></p>
|
| 311 |
-
<p>⚠️ For educational and research purposes. Always consult qualified healthcare professionals for medical decisions.</p>
|
| 312 |
-
<p>© 2025 SmartHeal. All rights reserved.</p>
|
| 313 |
-
</div>
|
| 314 |
-
""")
|
| 315 |
-
|
| 316 |
-
def format_risk_level_display(self, risk_level):
|
| 317 |
-
"""Format risk level with appropriate styling"""
|
| 318 |
-
if not risk_level or risk_level == "Unknown":
|
| 319 |
-
return "Risk Level: Unknown"
|
| 320 |
-
|
| 321 |
-
css_class = {
|
| 322 |
-
"Low": "risk-level-low",
|
| 323 |
-
"Minimal": "risk-level-low",
|
| 324 |
-
"Moderate": "risk-level-moderate",
|
| 325 |
-
"High": "risk-level-high"
|
| 326 |
-
}.get(risk_level, "")
|
| 327 |
-
|
| 328 |
-
if css_class:
|
| 329 |
-
return f'<div class="{css_class}"><strong>Risk Level: {risk_level}</strong></div>'
|
| 330 |
-
else:
|
| 331 |
-
return f"Risk Level: {risk_level}"
|
| 332 |
-
|
| 333 |
-
def create_info_card(self, title, content, icon="ℹ️"):
|
| 334 |
-
"""Create an information card"""
|
| 335 |
-
return gr.HTML(f"""
|
| 336 |
-
<div class="analysis-container">
|
| 337 |
-
<h4>{icon} {title}</h4>
|
| 338 |
-
<p>{content}</p>
|
| 339 |
-
</div>
|
| 340 |
-
""")
|
| 341 |
-
|
| 342 |
-
def create_loading_indicator(self, message="Processing..."):
|
| 343 |
-
"""Create loading indicator"""
|
| 344 |
-
return gr.HTML(f"""
|
| 345 |
-
<div style="text-align: center; padding: 1rem;">
|
| 346 |
-
<div class="loading"></div>
|
| 347 |
-
<p>{message}</p>
|
| 348 |
-
</div>
|
| 349 |
-
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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