Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,40 +84,7 @@ def image_to_base64(image):
|
|
| 84 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
| 85 |
return f"data:image/png;base64,{img_str}"
|
| 86 |
|
| 87 |
-
# Styles communs pour les deux pages
|
| 88 |
COMMON_STYLES = """
|
| 89 |
-
:root {
|
| 90 |
-
color-scheme: light dark;
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
@media (prefers-color-scheme: dark) {
|
| 94 |
-
body {
|
| 95 |
-
background: #1a1a1a !important;
|
| 96 |
-
color: #ffffff !important;
|
| 97 |
-
}
|
| 98 |
-
.container {
|
| 99 |
-
background: #2d2d2d !important;
|
| 100 |
-
}
|
| 101 |
-
.result-box, .upload-section {
|
| 102 |
-
background: #363636 !important;
|
| 103 |
-
border-color: #555 !important;
|
| 104 |
-
}
|
| 105 |
-
.button {
|
| 106 |
-
background: #0066cc !important;
|
| 107 |
-
}
|
| 108 |
-
input[type="file"]::file-selector-button {
|
| 109 |
-
background: #444 !important;
|
| 110 |
-
color: #fff !important;
|
| 111 |
-
border-color: #555 !important;
|
| 112 |
-
}
|
| 113 |
-
input[type="range"] {
|
| 114 |
-
background: #444 !important;
|
| 115 |
-
}
|
| 116 |
-
.button-progress {
|
| 117 |
-
background: rgba(255, 255, 255, 0.2) !important;
|
| 118 |
-
}
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
body {
|
| 122 |
font-family: system-ui, -apple-system, sans-serif;
|
| 123 |
background: #f0f2f5;
|
|
@@ -125,8 +92,6 @@ COMMON_STYLES = """
|
|
| 125 |
padding: 20px;
|
| 126 |
color: #1a1a1a;
|
| 127 |
}
|
| 128 |
-
|
| 129 |
-
/* Scrollbar personnalisée */
|
| 130 |
::-webkit-scrollbar {
|
| 131 |
width: 8px;
|
| 132 |
height: 8px;
|
|
@@ -141,12 +106,6 @@ COMMON_STYLES = """
|
|
| 141 |
border-radius: 4px;
|
| 142 |
}
|
| 143 |
|
| 144 |
-
@media (prefers-color-scheme: dark) {
|
| 145 |
-
::-webkit-scrollbar-thumb {
|
| 146 |
-
background-color: rgba(75, 85, 99, 0.5);
|
| 147 |
-
}
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
.container {
|
| 151 |
max-width: 1200px;
|
| 152 |
margin: 0 auto;
|
|
@@ -155,9 +114,8 @@ COMMON_STYLES = """
|
|
| 155 |
border-radius: 10px;
|
| 156 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 157 |
}
|
| 158 |
-
|
| 159 |
.button {
|
| 160 |
-
background: #
|
| 161 |
color: white;
|
| 162 |
border: none;
|
| 163 |
padding: 12px 30px;
|
|
@@ -167,21 +125,13 @@ COMMON_STYLES = """
|
|
| 167 |
transition: all 0.3s ease;
|
| 168 |
position: relative;
|
| 169 |
}
|
| 170 |
-
|
| 171 |
.button:hover {
|
| 172 |
-
background: #
|
| 173 |
}
|
| 174 |
-
|
| 175 |
-
/* Nouvelle barre de progression */
|
| 176 |
-
.button {
|
| 177 |
-
position: relative;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
@keyframes progress {
|
| 181 |
0% { width: 0; }
|
| 182 |
100% { width: 100%; }
|
| 183 |
}
|
| 184 |
-
|
| 185 |
.button-progress {
|
| 186 |
position: absolute;
|
| 187 |
bottom: 0;
|
|
@@ -190,16 +140,26 @@ COMMON_STYLES = """
|
|
| 190 |
background: rgba(255, 255, 255, 0.5);
|
| 191 |
width: 0;
|
| 192 |
}
|
| 193 |
-
|
| 194 |
.button:active .button-progress {
|
| 195 |
animation: progress 2s linear forwards;
|
| 196 |
}
|
| 197 |
-
|
| 198 |
img {
|
| 199 |
max-width: 100%;
|
| 200 |
height: auto;
|
| 201 |
border-radius: 8px;
|
| 202 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
"""
|
| 204 |
|
| 205 |
@app.get("/", response_class=HTMLResponse)
|
|
@@ -214,69 +174,66 @@ async def main():
|
|
| 214 |
{COMMON_STYLES}
|
| 215 |
|
| 216 |
.upload-section {{
|
| 217 |
-
background: #
|
| 218 |
padding: 40px;
|
| 219 |
border-radius: 12px;
|
| 220 |
margin: 20px 0;
|
| 221 |
text-align: center;
|
| 222 |
-
border: 2px dashed #
|
| 223 |
transition: all 0.3s ease;
|
|
|
|
| 224 |
}}
|
| 225 |
-
|
| 226 |
.upload-section:hover {{
|
| 227 |
-
border-color: #
|
| 228 |
}}
|
| 229 |
-
|
| 230 |
input[type="file"] {{
|
| 231 |
font-size: 1.1em;
|
| 232 |
margin: 20px 0;
|
|
|
|
| 233 |
}}
|
| 234 |
-
|
| 235 |
input[type="file"]::file-selector-button {{
|
| 236 |
font-size: 1em;
|
| 237 |
padding: 10px 20px;
|
| 238 |
border-radius: 8px;
|
| 239 |
-
border: 1px solid #
|
| 240 |
-
background: #
|
|
|
|
| 241 |
transition: all 0.3s ease;
|
| 242 |
cursor: pointer;
|
| 243 |
}}
|
| 244 |
-
|
| 245 |
input[type="file"]::file-selector-button:hover {{
|
| 246 |
-
background: #
|
| 247 |
}}
|
| 248 |
-
|
| 249 |
.confidence-slider {{
|
| 250 |
width: 100%;
|
| 251 |
max-width: 300px;
|
| 252 |
margin: 20px auto;
|
| 253 |
}}
|
| 254 |
-
|
| 255 |
input[type="range"] {{
|
| 256 |
width: 100%;
|
| 257 |
height: 8px;
|
| 258 |
border-radius: 4px;
|
| 259 |
-
background: #
|
| 260 |
outline: none;
|
| 261 |
transition: all 0.3s ease;
|
| 262 |
-webkit-appearance: none;
|
| 263 |
}}
|
| 264 |
-
|
| 265 |
input[type="range"]::-webkit-slider-thumb {{
|
| 266 |
-webkit-appearance: none;
|
| 267 |
width: 20px;
|
| 268 |
height: 20px;
|
| 269 |
border-radius: 50%;
|
| 270 |
-
background:
|
| 271 |
cursor: pointer;
|
| 272 |
border: none;
|
| 273 |
}}
|
| 274 |
</style>
|
| 275 |
</head>
|
| 276 |
<body>
|
|
|
|
| 277 |
<div class="container">
|
| 278 |
<div class="upload-section">
|
| 279 |
-
<form action="/analyze" method="post" enctype="multipart/form-data">
|
| 280 |
<div>
|
| 281 |
<input type="file" name="file" accept="image/*" required>
|
| 282 |
</div>
|
|
@@ -331,15 +288,13 @@ async def analyze_file(file: UploadFile = File(...)):
|
|
| 331 |
gap: 20px;
|
| 332 |
margin-top: 20px;
|
| 333 |
}}
|
| 334 |
-
|
| 335 |
.result-box {{
|
| 336 |
-
background:
|
| 337 |
padding: 20px;
|
| 338 |
border-radius: 12px;
|
| 339 |
margin: 10px 0;
|
| 340 |
border: 1px solid #e9ecef;
|
| 341 |
}}
|
| 342 |
-
|
| 343 |
.score-high {{
|
| 344 |
color: #0066cc;
|
| 345 |
font-weight: bold;
|
|
@@ -349,24 +304,15 @@ async def analyze_file(file: UploadFile = File(...)):
|
|
| 349 |
color: #ffa500;
|
| 350 |
font-weight: bold;
|
| 351 |
}}
|
| 352 |
-
|
| 353 |
.back-button {{
|
| 354 |
display: inline-block;
|
| 355 |
text-decoration: none;
|
| 356 |
margin-top: 20px;
|
| 357 |
}}
|
| 358 |
-
|
| 359 |
h3 {{
|
| 360 |
color: #0066cc;
|
| 361 |
margin-top: 0;
|
| 362 |
}}
|
| 363 |
-
|
| 364 |
-
@media (prefers-color-scheme: dark) {{
|
| 365 |
-
h3 {{
|
| 366 |
-
color: #66b3ff;
|
| 367 |
-
}}
|
| 368 |
-
}}
|
| 369 |
-
|
| 370 |
@media (max-width: 768px) {{
|
| 371 |
.results-grid {{
|
| 372 |
grid-template-columns: 1fr;
|
|
@@ -378,10 +324,9 @@ async def analyze_file(file: UploadFile = File(...)):
|
|
| 378 |
<div class="container">
|
| 379 |
<div class="results-grid">
|
| 380 |
<div>
|
|
|
|
| 381 |
"""
|
| 382 |
|
| 383 |
-
# KnochenWächter results
|
| 384 |
-
results_html += "<div class='result-box'><h3>KnochenWächter</h3>"
|
| 385 |
for pred in predictions_watcher:
|
| 386 |
confidence_class = "score-high" if pred['score'] > 0.7 else "score-medium"
|
| 387 |
results_html += f"""
|
|
@@ -392,7 +337,6 @@ async def analyze_file(file: UploadFile = File(...)):
|
|
| 392 |
"""
|
| 393 |
results_html += "</div>"
|
| 394 |
|
| 395 |
-
# RöntgenMeister results
|
| 396 |
results_html += "<div class='result-box'><h3>RöntgenMeister</h3>"
|
| 397 |
for pred in predictions_master:
|
| 398 |
confidence_class = "score-high" if pred['score'] > 0.7 else "score-medium"
|
|
@@ -404,7 +348,6 @@ async def analyze_file(file: UploadFile = File(...)):
|
|
| 404 |
"""
|
| 405 |
results_html += "</div></div>"
|
| 406 |
|
| 407 |
-
# Image result
|
| 408 |
results_html += f"""
|
| 409 |
<div class='result-box'>
|
| 410 |
<h3>Fraktur Lokalisation</h3>
|
|
@@ -439,12 +382,6 @@ async def analyze_file(file: UploadFile = File(...)):
|
|
| 439 |
border-radius: 8px;
|
| 440 |
margin: 20px 0;
|
| 441 |
}}
|
| 442 |
-
@media (prefers-color-scheme: dark) {{
|
| 443 |
-
.error-box {{
|
| 444 |
-
background: #471818;
|
| 445 |
-
border-color: #dc2626;
|
| 446 |
-
}}
|
| 447 |
-
}}
|
| 448 |
</style>
|
| 449 |
</head>
|
| 450 |
<body>
|
|
|
|
| 84 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
| 85 |
return f"data:image/png;base64,{img_str}"
|
| 86 |
|
|
|
|
| 87 |
COMMON_STYLES = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
body {
|
| 89 |
font-family: system-ui, -apple-system, sans-serif;
|
| 90 |
background: #f0f2f5;
|
|
|
|
| 92 |
padding: 20px;
|
| 93 |
color: #1a1a1a;
|
| 94 |
}
|
|
|
|
|
|
|
| 95 |
::-webkit-scrollbar {
|
| 96 |
width: 8px;
|
| 97 |
height: 8px;
|
|
|
|
| 106 |
border-radius: 4px;
|
| 107 |
}
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
.container {
|
| 110 |
max-width: 1200px;
|
| 111 |
margin: 0 auto;
|
|
|
|
| 114 |
border-radius: 10px;
|
| 115 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 116 |
}
|
|
|
|
| 117 |
.button {
|
| 118 |
+
background: #2d2d2d;
|
| 119 |
color: white;
|
| 120 |
border: none;
|
| 121 |
padding: 12px 30px;
|
|
|
|
| 125 |
transition: all 0.3s ease;
|
| 126 |
position: relative;
|
| 127 |
}
|
|
|
|
| 128 |
.button:hover {
|
| 129 |
+
background: #404040;
|
| 130 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
@keyframes progress {
|
| 132 |
0% { width: 0; }
|
| 133 |
100% { width: 100%; }
|
| 134 |
}
|
|
|
|
| 135 |
.button-progress {
|
| 136 |
position: absolute;
|
| 137 |
bottom: 0;
|
|
|
|
| 140 |
background: rgba(255, 255, 255, 0.5);
|
| 141 |
width: 0;
|
| 142 |
}
|
|
|
|
| 143 |
.button:active .button-progress {
|
| 144 |
animation: progress 2s linear forwards;
|
| 145 |
}
|
|
|
|
| 146 |
img {
|
| 147 |
max-width: 100%;
|
| 148 |
height: auto;
|
| 149 |
border-radius: 8px;
|
| 150 |
}
|
| 151 |
+
#loading {
|
| 152 |
+
display: none;
|
| 153 |
+
position: fixed;
|
| 154 |
+
top: 50%;
|
| 155 |
+
left: 50%;
|
| 156 |
+
transform: translate(-50%, -50%);
|
| 157 |
+
background: #2d2d2d;
|
| 158 |
+
color: white;
|
| 159 |
+
padding: 20px;
|
| 160 |
+
border-radius: 8px;
|
| 161 |
+
z-index: 1000;
|
| 162 |
+
}
|
| 163 |
"""
|
| 164 |
|
| 165 |
@app.get("/", response_class=HTMLResponse)
|
|
|
|
| 174 |
{COMMON_STYLES}
|
| 175 |
|
| 176 |
.upload-section {{
|
| 177 |
+
background: #2d2d2d;
|
| 178 |
padding: 40px;
|
| 179 |
border-radius: 12px;
|
| 180 |
margin: 20px 0;
|
| 181 |
text-align: center;
|
| 182 |
+
border: 2px dashed #404040;
|
| 183 |
transition: all 0.3s ease;
|
| 184 |
+
color: white;
|
| 185 |
}}
|
|
|
|
| 186 |
.upload-section:hover {{
|
| 187 |
+
border-color: #555;
|
| 188 |
}}
|
|
|
|
| 189 |
input[type="file"] {{
|
| 190 |
font-size: 1.1em;
|
| 191 |
margin: 20px 0;
|
| 192 |
+
color: white;
|
| 193 |
}}
|
|
|
|
| 194 |
input[type="file"]::file-selector-button {{
|
| 195 |
font-size: 1em;
|
| 196 |
padding: 10px 20px;
|
| 197 |
border-radius: 8px;
|
| 198 |
+
border: 1px solid #404040;
|
| 199 |
+
background: #2d2d2d;
|
| 200 |
+
color: white;
|
| 201 |
transition: all 0.3s ease;
|
| 202 |
cursor: pointer;
|
| 203 |
}}
|
|
|
|
| 204 |
input[type="file"]::file-selector-button:hover {{
|
| 205 |
+
background: #404040;
|
| 206 |
}}
|
|
|
|
| 207 |
.confidence-slider {{
|
| 208 |
width: 100%;
|
| 209 |
max-width: 300px;
|
| 210 |
margin: 20px auto;
|
| 211 |
}}
|
|
|
|
| 212 |
input[type="range"] {{
|
| 213 |
width: 100%;
|
| 214 |
height: 8px;
|
| 215 |
border-radius: 4px;
|
| 216 |
+
background: #404040;
|
| 217 |
outline: none;
|
| 218 |
transition: all 0.3s ease;
|
| 219 |
-webkit-appearance: none;
|
| 220 |
}}
|
|
|
|
| 221 |
input[type="range"]::-webkit-slider-thumb {{
|
| 222 |
-webkit-appearance: none;
|
| 223 |
width: 20px;
|
| 224 |
height: 20px;
|
| 225 |
border-radius: 50%;
|
| 226 |
+
background: white;
|
| 227 |
cursor: pointer;
|
| 228 |
border: none;
|
| 229 |
}}
|
| 230 |
</style>
|
| 231 |
</head>
|
| 232 |
<body>
|
| 233 |
+
<div id="loading">Loading...</div>
|
| 234 |
<div class="container">
|
| 235 |
<div class="upload-section">
|
| 236 |
+
<form action="/analyze" method="post" enctype="multipart/form-data" onsubmit="document.getElementById('loading').style.display = 'block';">
|
| 237 |
<div>
|
| 238 |
<input type="file" name="file" accept="image/*" required>
|
| 239 |
</div>
|
|
|
|
| 288 |
gap: 20px;
|
| 289 |
margin-top: 20px;
|
| 290 |
}}
|
|
|
|
| 291 |
.result-box {{
|
| 292 |
+
background: white;
|
| 293 |
padding: 20px;
|
| 294 |
border-radius: 12px;
|
| 295 |
margin: 10px 0;
|
| 296 |
border: 1px solid #e9ecef;
|
| 297 |
}}
|
|
|
|
| 298 |
.score-high {{
|
| 299 |
color: #0066cc;
|
| 300 |
font-weight: bold;
|
|
|
|
| 304 |
color: #ffa500;
|
| 305 |
font-weight: bold;
|
| 306 |
}}
|
|
|
|
| 307 |
.back-button {{
|
| 308 |
display: inline-block;
|
| 309 |
text-decoration: none;
|
| 310 |
margin-top: 20px;
|
| 311 |
}}
|
|
|
|
| 312 |
h3 {{
|
| 313 |
color: #0066cc;
|
| 314 |
margin-top: 0;
|
| 315 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
@media (max-width: 768px) {{
|
| 317 |
.results-grid {{
|
| 318 |
grid-template-columns: 1fr;
|
|
|
|
| 324 |
<div class="container">
|
| 325 |
<div class="results-grid">
|
| 326 |
<div>
|
| 327 |
+
<div class="result-box"><h3>KnochenWächter</h3>
|
| 328 |
"""
|
| 329 |
|
|
|
|
|
|
|
| 330 |
for pred in predictions_watcher:
|
| 331 |
confidence_class = "score-high" if pred['score'] > 0.7 else "score-medium"
|
| 332 |
results_html += f"""
|
|
|
|
| 337 |
"""
|
| 338 |
results_html += "</div>"
|
| 339 |
|
|
|
|
| 340 |
results_html += "<div class='result-box'><h3>RöntgenMeister</h3>"
|
| 341 |
for pred in predictions_master:
|
| 342 |
confidence_class = "score-high" if pred['score'] > 0.7 else "score-medium"
|
|
|
|
| 348 |
"""
|
| 349 |
results_html += "</div></div>"
|
| 350 |
|
|
|
|
| 351 |
results_html += f"""
|
| 352 |
<div class='result-box'>
|
| 353 |
<h3>Fraktur Lokalisation</h3>
|
|
|
|
| 382 |
border-radius: 8px;
|
| 383 |
margin: 20px 0;
|
| 384 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
</style>
|
| 386 |
</head>
|
| 387 |
<body>
|