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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>SkinAI - Results</title>
  <style>
    /* Reset */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      font-family: Arial, sans-serif;
      background-color: #f5f8fa;
      color: #000;
    }

    /* Top Navigation with Enhanced Hover Effects */
    header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 15px 5%;
      background-color: #fff;
      border-bottom: 1px solid #ccc;
      position: relative;
      z-index: 10;
    }
    
    .logo {
      font-size: 1.5rem;
      font-weight: bold;
      color: #333;
    }
    
    nav a {
      text-decoration: none;
      color: #333;
      margin-left: 20px;
      font-weight: 500;
      padding: 5px 0;
      position: relative;
      transition: color 0.3s ease;
    }
    
    /* Underline hover effect for nav links */
    nav a:after {
      content: '';
      position: absolute;
      width: 0;
      height: 2px;
      bottom: 0;
      left: 0;
      background-color: #007BFF;
      transition: width 0.3s ease;
    }
    
    nav a:hover {
      color: #007BFF;
      text-decoration: none;
    }
    
    nav a:hover:after {
      width: 100%;
    }
    
    .help-btn {
      background-color: #007BFF;
      color: #fff;
      border: none;
      padding: 8px 16px;
      border-radius: 4px;
      cursor: pointer;
      margin-left: 20px;
      transition: all 0.3s ease;
    }
    
    .help-btn:hover {
      background-color: #0056b3;
      transform: translateY(-2px);
      box-shadow: 0 4px 8px rgba(0,123,255,0.3);
    }

    /* Main Content Area */
    .container {
      max-width: 1200px;
      margin: 40px auto;
      padding: 0 20px;
    }

    /* Results Section */
    .results-section {
      background-color: #fff;
      border-radius: 10px;
      box-shadow: 0 5px 15px rgba(0,0,0,0.08);
      padding: 40px;
      margin-bottom: 40px;
    }

    .results-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 30px;
    }

    .results-header h1 {
      font-size: 2rem;
      color: #333;
    }

    .results-header .new-analysis {
      background-color: #f8f9fa;
      color: #333;
      border: 1px solid #ddd;
      padding: 8px 16px;
      border-radius: 4px;
      text-decoration: none;
      transition: all 0.3s ease;
    }

    .results-header .new-analysis:hover {
      background-color: #e9ecef;
      transform: translateY(-2px);
    }

    /* Results Grid */
    .results-grid {
      display: grid;
      grid-template-columns: 1fr 2fr;
      gap: 30px;
    }

    /* Image Section */
    .image-section {
      background-color: #f8f9fa;
      border-radius: 8px;
      padding: 20px;
      text-align: center;
    }

    .image-section img {
      max-width: 100%;
      max-height: 300px;
      border-radius: 8px;
      margin-bottom: 15px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }

    .image-caption {
      font-size: 0.9rem;
      color: #666;
    }

    /* Analysis Section */
    .analysis-section {
      display: flex;
      flex-direction: column;
      gap: 20px;
    }

    .analysis-card {
      background-color: #f8f9fa;
      border-radius: 8px;
      padding: 20px;
      border-left: 4px solid #007BFF;
    }

    .analysis-card h2 {
      font-size: 1.4rem;
      color: #333;
      margin-bottom: 10px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .confidence-badge {
      background-color: #e6f4ff;
      color: #0066cc;
      font-size: 0.9rem;
      padding: 4px 12px;
      border-radius: 20px;
      font-weight: normal;
    }

    .analysis-card p {
      font-size: 1rem;
      color: #555;
      line-height: 1.6;
      margin-bottom: 15px;
    }

    /* Recommendations List */
    .recommendations-list {
      margin-top: 10px;
    }

    .recommendations-list h3 {
      font-size: 1.1rem;
      color: #333;
      margin-bottom: 15px;
    }

    .recommendations-list ul {
      padding-left: 20px;
    }

    .recommendations-list li {
      margin-bottom: 10px;
      line-height: 1.5;
      font-size: 0.95rem;
      color: #444;
    }

    /* Other Possible Conditions */
    .other-conditions {
      margin-top: 20px;
    }

    .other-conditions h3 {
      font-size: 1.1rem;
      color: #333;
      margin-bottom: 15px;
    }

    .condition-bars {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .condition-bar {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .condition-name {
      min-width: 100px;
      font-size: 0.9rem;
    }

    .progress-bar {
      flex-grow: 1;
      height: 10px;
      background-color: #e9ecef;
      border-radius: 5px;
      overflow: hidden;
    }

    .progress-fill {
      height: 100%;
      background-color: #007BFF;
    }

    .condition-percentage {
      font-size: 0.9rem;
      color: #666;
      min-width: 50px;
      text-align: right;
    }

    /* Q&A Section */
    .qa-section {
      background-color: #fff;
      border-radius: 10px;
      box-shadow: 0 5px 15px rgba(0,0,0,0.08);
      padding: 40px;
    }

    .qa-section h2 {
      font-size: 1.6rem;
      color: #333;
      margin-bottom: 25px;
    }

    .qa-form {
      display: flex;
      gap: 10px;
      margin-bottom: 30px;
    }

    .qa-input {
      flex-grow: 1;
      padding: 12px 15px;
      border: 1px solid #ddd;
      border-radius: 4px;
      font-size: 1rem;
    }

    .qa-btn {
      background-color: #007BFF;
      color: #fff;
      border: none;
      padding: 0 20px;
      border-radius: 4px;
      cursor: pointer;
      transition: all 0.3s ease;
    }

    .qa-btn:hover {
      background-color: #0056b3;
    }

    .qa-response {
      background-color: #f8f9fa;
      border-radius: 8px;
      padding: 20px;
      border-left: 4px solid #28a745;
      margin-bottom: 20px;
      display: none; /* Initially hidden */
    }

    .qa-response h3 {
      font-size: 1.1rem;
      color: #333;
      margin-bottom: 10px;
    }

    .qa-response p {
      font-size: 0.95rem;
      color: #555;
      line-height: 1.6;
    }

    .disclaimer {
      margin-top: 20px;
      padding: 15px;
      background-color: #fff8e1;
      border-left: 4px solid #ffc107;
      font-size: 0.9rem;
      color: #6c4a00;
      line-height: 1.5;
    }

    /* Footer */
    footer {
      text-align: center;
      padding: 20px;
      margin-top: 40px;
      color: #777;
      font-size: 0.9rem;
    }

    /* Loader */
    .loader-container {
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 20px 0;
    }

    .loader {
      border: 4px solid #f3f3f3;
      border-top: 4px solid #007BFF;
      border-radius: 50%;
      width: 30px;
      height: 30px;
      animation: spin 1s linear infinite;
      margin-right: 10px;
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }

    /* Responsive */
    @media (max-width: 768px) {
      .container {
        padding: 0 15px;
        margin: 20px auto;
      }
      
      .results-section, .qa-section {
        padding: 30px 15px;
      }
      
      .results-grid {
        grid-template-columns: 1fr;
      }
      
      .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
      }
    }
  </style>
</head>
<body>

  <!-- Top Navigation -->
  <header>
    <div class="logo">SkinAI</div>
    <nav>
      <a href="/">Home</a>
      <a href="/upload">Upload</a>
      <a href="/result" style="color: #007BFF;">Results</a>
      <a href="#">Contact</a>
      <button class="help-btn">Help</button>
    </nav>
  </header>

  <div class="container">
    <!-- Results Section -->
    <section class="results-section">
      <div class="results-header">
        <h1>Analysis Results</h1>
        <a href="upload" class="new-analysis">Upload New Image</a>
      </div>
      
      <div class="results-grid">
        <!-- Image Section -->
        <div class="image-section">
          <img id="analyzed-image" src="#" alt="Analyzed Skin Image">
          <div class="image-caption">Uploaded on <span id="upload-date">April 8, 2025</span></div>
        </div>
        
        <!-- Analysis Section -->
        <div class="analysis-section">
          <div class="analysis-card">
            <h2>
              <span id="condition-name">Loading result...</span>
              <span class="confidence-badge" id="confidence-level">--</span>
            </h2>
            <p id="condition-description">Analyzing your image...</p>
            
            <!-- Loader (initially shown) -->
            <div class="loader-container" id="analysis-loader">
              <div class="loader"></div>
              <span>Processing image with AI...</span>
            </div>
            
            <!-- Recommendations (initially hidden) -->
            <div class="recommendations-list" id="recommendations-section" style="display: none;">
              <h3>Recommendations</h3>
              <ul id="recommendations-list">
                <!-- Recommendations will be inserted here -->
              </ul>
            </div>
            
            <!-- Other Possible Conditions -->
            <div class="other-conditions" id="other-conditions-section" style="display: none;">
              <h3>Other Possible Conditions</h3>
              <div class="condition-bars" id="condition-bars">
                <!-- Condition bars will be inserted here -->
              </div>
            </div>
          </div>
          
          <div class="disclaimer">
            <strong>Disclaimer:</strong> This analysis is for informational purposes only and should not replace professional medical advice. Please consult a healthcare provider for proper diagnosis and treatment.
          </div>
        </div>
      </div>
    </section>
    
    <!-- Q&A Section -->
    <section class="qa-section">
      <h2>Ask About Your Condition</h2>
      <div class="qa-form">
        <input type="text" class="qa-input" id="question-input" placeholder="Ask a question about your skin condition...">
        <button class="qa-btn" id="ask-btn">Ask</button>
      </div>
      
      <!-- QA Response (initially hidden) -->
      <div class="qa-response" id="qa-response">
        <h3>Response</h3>
        <p id="qa-answer">The answer will appear here.</p>
      </div>
      
      <div class="disclaimer">
        <strong>Important:</strong> The AI assistant provides general information about skin conditions. Your specific case may vary, and medical professionals should be consulted for personalized advice and treatment.
      </div>
    </section>
  </div>

  <footer>
    <p>© 2025 SkinAI. All rights reserved. For educational purposes only. Not a substitute for professional medical advice.</p>
  </footer>

  <script>
    document.addEventListener('DOMContentLoaded', function() {
      // Retrieve data from sessionStorage (set during upload)
      const imageData = sessionStorage.getItem('analyzedImage');
      const analysisResult = JSON.parse(sessionStorage.getItem('analysisResult') || '{}');
      const condition = sessionStorage.getItem('detectedCondition') || '';
      
      // Set the image
      if (imageData) {
        document.getElementById('analyzed-image').src = imageData;
      } else {
        document.getElementById('analyzed-image').src = "/api/placeholder/400/320";
        document.getElementById('analyzed-image').alt = "No image available";
      }
      
      // Set the current date
      const now = new Date();
      document.getElementById('upload-date').textContent = now.toLocaleDateString('en-US', { 
        year: 'numeric', 
        month: 'long', 
        day: 'numeric' 
      });
      
      // Process and display results if available
      if (Object.keys(analysisResult).length > 0) {
        displayResults(analysisResult);
      } else {
        // If no results in session storage, check URL params
        // This allows direct navigation to this page with the results as parameters
        const urlParams = new URLSearchParams(window.location.search);
        const resultParam = urlParams.get('result');
        
        if (resultParam) {
          try {
            const decodedResult = JSON.parse(decodeURIComponent(resultParam));
            displayResults(decodedResult);
          } catch (e) {
            console.error("Failed to parse result from URL parameter", e);
            document.getElementById('condition-name').textContent = "No results available";
            document.getElementById('condition-description').textContent = "Please upload an image for analysis.";
            document.getElementById('analysis-loader').style.display = "none";
          }
        } else {
          // No results available - show message
          document.getElementById('condition-name').textContent = "No results available";
          document.getElementById('condition-description').textContent = "Please upload an image for analysis.";
          document.getElementById('analysis-loader').style.display = "none";
        }
      }
      
      // Handle Q&A form submission
      document.getElementById('ask-btn').addEventListener('click', function() {
        askQuestion();
      });
      
      document.getElementById('question-input').addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
          askQuestion();
        }
      });
      
      // Function to display analysis results
      function displayResults(result) {
        // Hide loader
        document.getElementById('analysis-loader').style.display = "none";
        
        // Display primary condition and confidence
        document.getElementById('condition-name').textContent = result.prediction || "Unknown Condition";
        
        const confidencePercent = result.confidence ? Math.round(result.confidence * 100) : 0;
        document.getElementById('confidence-level').textContent = `${confidencePercent}% Confidence`;
        
        // Display description
        document.getElementById('condition-description').textContent = result.description || 
          "No detailed information available for this condition.";
        
        // Display recommendations
        if (result.recommendations && result.recommendations.length > 0) {
          const recommendationsList = document.getElementById('recommendations-list');
          recommendationsList.innerHTML = '';
          
          result.recommendations.forEach(rec => {
            const li = document.createElement('li');
            li.textContent = rec;
            recommendationsList.appendChild(li);
          });
          
          document.getElementById('recommendations-section').style.display = "block";
        }
        
        // Display other possible conditions
        if (result.topConditions && result.topConditions.length > 0) {
          const conditionBars = document.getElementById('condition-bars');
          conditionBars.innerHTML = '';
          
          // Skip the first condition (already shown as primary) if it's the same as the top result
          const startIndex = (result.topConditions[0][0] === result.prediction) ? 1 : 0;
          
          // Display up to 4 additional conditions
          for (let i = startIndex; i < Math.min(startIndex + 4, result.topConditions.length); i++) {
            const condition = result.topConditions[i];
            const conditionName = condition[0];
            const probability = condition[1];
            const percentage = Math.round(probability * 100);
            
            const conditionBar = document.createElement('div');
            conditionBar.className = 'condition-bar';
            conditionBar.innerHTML = `
              <div class="condition-name">${conditionName}</div>
              <div class="progress-bar">
                <div class="progress-fill" style="width: ${percentage}%"></div>
              </div>
              <div class="condition-percentage">${percentage}%</div>
            `;
            
            conditionBars.appendChild(conditionBar);
          }
          
          document.getElementById('other-conditions-section').style.display = "block";
        }
        
        // Store detected condition for Q&A
        sessionStorage.setItem('detectedCondition', result.prediction || '');
      }
      
      // Function to handle Q&A
      function askQuestion() {
        const questionInput = document.getElementById('question-input');
        const question = questionInput.value.trim();
        
        if (!question) return;
        
        // Get the detected condition
        const detectedCondition = sessionStorage.getItem('detectedCondition') || '';
        
        // Show loading indication
        document.getElementById('qa-answer').textContent = "Getting answer...";
        document.getElementById('qa-response').style.display = "block";
        
        // Call the backend API
        fetch('/ask', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            question: question,
            condition: detectedCondition
          })
        })
        .then(response => response.json())
        .then(data => {
          document.getElementById('qa-answer').textContent = data.answer || 
            "I couldn't generate an answer for that question.";
        })
        .catch(error => {
          console.error('Error:', error);
          document.getElementById('qa-answer').textContent = 
            "Sorry, there was an error processing your question. Please try again later.";
        });
        
        // Clear the input
        questionInput.value = '';
      }
    });
  </script>

</body>
</html>