Yash goyal commited on
Commit
539f115
·
verified ·
1 Parent(s): 6ce4f94

Update templates/form.html

Browse files
Files changed (1) hide show
  1. templates/form.html +108 -65
templates/form.html CHANGED
@@ -3,89 +3,132 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>New Scan | SnapSkin</title>
7
  <link rel="stylesheet" href="{{ url_for('static', filename='form-styles.css') }}">
8
  <link rel="icon" type="image/png" href="{{ url_for('static', filename='logo.png') }}">
9
  </head>
10
  <body>
11
- <header>
12
- <nav>
13
- <div class="logo">SNAP<span>SKIN</span></div>
14
- <ul>
15
- {% if current_user.is_authenticated %}
16
- <li><a href="{{ url_for('history') }}">My History</a></li>
17
- <li><a href="{{ url_for('logout') }}">Logout</a></li>
18
- {% else %}
19
- <li><a href="{{ url_for('login') }}">Login</a></li>
20
- {% endif %}
21
- </ul>
22
- </nav>
23
- </header>
24
-
25
  <div class="container">
26
  <header>
27
- <h1>Start a New Diagnosis</h1>
28
- <p>Upload a skin lesion image to get an AI-powered analysis.</p>
29
  </header>
30
 
31
- {% if current_user.is_authenticated %}
32
- <form id="diagnosis-form" action="{{ url_for('predict') }}" method="POST" enctype="multipart/form-data">
33
- <div class="form-group">
34
- <label for="gender">Gender:</label>
35
- <select id="gender" name="gender" required>
36
- <option value="" disabled selected>Select your gender</option>
37
- <option value="Male">Male</option>
38
- <option value="Female">Female</option>
39
- <option value="Other">Other</option>
40
- </select>
41
- </div>
42
- <div class="form-group">
43
- <label for="age">Age:</label>
44
- <input type="number" id="age" name="age" min="0" max="150" placeholder="e.g., 35" required>
45
- </div>
46
- <div class="form-group">
47
- <label for="image">Upload Skin Image:</label>
48
- <input type="file" id="image" name="image" accept="image/*" required>
49
- <label for="image" class="file-upload-label" id="file-upload-text">Click to choose an image</label>
50
- </div>
51
- <button type="submit" class="submit-button" id="submit-btn">Diagnose</button>
52
- </form>
53
- {% else %}
54
- <div class="alert alert-warning" style="text-align: center; margin-top: 2rem;">
55
- <p>Please <a href="{{ url_for('login') }}" style="color: var(--primary-glow); text-decoration: underline;">log in</a> to start a new diagnosis.</p>
56
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  {% endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  </div>
59
 
60
  <script src="{{ url_for('static', filename='preloader.js') }}"></script>
61
  <script src="{{ url_for('static', filename='cursor-effect.js') }}"></script>
62
-
63
  <script>
64
- const fileInput = document.getElementById('image');
65
- const fileUploadText = document.getElementById('file-upload-text');
66
- const diagnosisForm = document.getElementById('diagnosis-form');
67
- const submitBtn = document.getElementById('submit-btn');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- if (fileInput) {
70
- fileInput.addEventListener('change', () => {
71
- if (fileInput.files.length > 0) {
72
- fileUploadText.textContent = fileInput.files[0].name;
73
- fileUploadText.classList.add('file-selected');
74
- } else {
75
- fileUploadText.textContent = 'Click to choose an image';
76
- fileUploadText.classList.remove('file-selected');
77
- }
78
- });
79
  }
80
 
81
- if (diagnosisForm) {
82
- diagnosisForm.addEventListener('submit', () => {
83
- if(submitBtn) {
84
- submitBtn.disabled = true;
85
- submitBtn.textContent = 'Processing...';
86
- }
87
- });
88
- }
89
  </script>
90
  </body>
91
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>SnapSkin - Skin Lesion Diagnosis</title>
7
  <link rel="stylesheet" href="{{ url_for('static', filename='form-styles.css') }}">
8
  <link rel="icon" type="image/png" href="{{ url_for('static', filename='logo.png') }}">
9
  </head>
10
  <body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  <div class="container">
12
  <header>
13
+ <h1>SnapSkin</h1>
14
+ <p>AI-Powered Skin Lesion Diagnosis</p>
15
  </header>
16
 
17
+ <form id="diagnosis-form" action="{{ url_for('predict') }}" method="POST" enctype="multipart/form-data">
18
+ <div class="form-group">
19
+ <label for="name">Full Name:</label>
20
+ <input type="text" id="name" name="name" required>
21
+ </div>
22
+ <div class="form-group">
23
+ <label for="email">Email:</label>
24
+ <input type="email" id="email" name="email" required>
25
+ </div>
26
+ <div class="form-group">
27
+ <label for="gender">Gender:</label>
28
+ <select id="gender" name="gender" required>
29
+ <option value="Male">Male</option>
30
+ <option value="Female">Female</option>
31
+ <option value="Other">Other</option>
32
+ </select>
 
 
 
 
 
 
 
 
 
33
  </div>
34
+ <div class="form-group">
35
+ <label for="age">Age:</label>
36
+ <input type="number" id="age" name="age" min="0" max="150" required>
37
+ </div>
38
+ <div class="form-group">
39
+ <label for="image">Upload Skin Image:</label>
40
+ <input type="file" id="image" name="image" accept="image/*" required>
41
+ </div>
42
+ <button type="submit" id="submit-btn">Diagnose</button>
43
+ </form>
44
+
45
+ {% if result %}
46
+ <div class="result">
47
+ <h2>Diagnosis Result</h2>
48
+ <p><strong>Condition:</strong> {{ result.prediction }}</p>
49
+ <p><strong>Confidence:</strong> {{ result.confidence }}</p>
50
+ {% if result.message %}
51
+ <p><strong>Message:</strong> {{ result.message }}</p>
52
+ {% endif %}
53
+ <p id="email-status" style="color: {% if 'Failed' in result.email_status %}red{% else %}limegreen{% endif %}">{{ result.email_status }}</p>
54
+ {% if result.scan_id %}
55
+ <button id="resend-email-btn" data-scan-id="{{ result.scan_id }}">Resend Report to Email</button>
56
+ {% endif %}
57
+ <a href="{{ url_for('download_report') }}" id="download-btn">Download Report</a>
58
+ </div>
59
  {% endif %}
60
+
61
+ {% if history_plot %}
62
+ <div class="training-history">
63
+ <h2>Model Training History</h2>
64
+ <img src="{{ history_plot }}" alt="Training History Plot">
65
+ </div>
66
+ {% endif %}
67
+
68
+ <div id="history-section">
69
+ <h2>Previous Scans</h2>
70
+ <input type="email" id="history-email" placeholder="Enter email to view history">
71
+ <button id="fetch-history-btn">View History</button>
72
+ <div id="history-results"></div>
73
+ </div>
74
  </div>
75
 
76
  <script src="{{ url_for('static', filename='preloader.js') }}"></script>
77
  <script src="{{ url_for('static', filename='cursor-effect.js') }}"></script>
 
78
  <script>
79
+ document.getElementById('fetch-history-btn').addEventListener('click', () => {
80
+ const email = document.getElementById('history-email').value;
81
+ if (!email) {
82
+ alert('Please enter an email address.');
83
+ return;
84
+ }
85
+ fetch(`/api/history?email=${encodeURIComponent(email)}`)
86
+ .then(response => response.json())
87
+ .then(data => {
88
+ const historyDiv = document.getElementById('history-results');
89
+ historyDiv.innerHTML = '';
90
+ if (data.length === 0) {
91
+ historyDiv.innerHTML = '<p>No scan history found for this email.</p>';
92
+ return;
93
+ }
94
+ const ul = document.createElement('ul');
95
+ data.forEach(scan => {
96
+ const li = document.createElement('li');
97
+ li.innerHTML = `
98
+ <p><strong>Scan ID:</strong> ${scan.id}</p>
99
+ <p><strong>Patient:</strong> ${scan.patient_name}</p>
100
+ <p><strong>Prediction:</strong> ${scan.prediction}</p>
101
+ <p><strong>Confidence:</strong> ${scan.confidence}</p>
102
+ <p><strong>Timestamp:</strong> ${scan.timestamp}</p>
103
+ <img src="${scan.image_url}" alt="Scan Image" style="max-width: 200px;">
104
+ <button onclick="resendEmail(${scan.id})">Resend Report</button>
105
+ `;
106
+ ul.appendChild(li);
107
+ });
108
+ historyDiv.appendChild(ul);
109
+ })
110
+ .catch(error => {
111
+ console.error('Error fetching history:', error);
112
+ document.getElementById('history-results').innerHTML = '<p>Error loading history. Please try again.</p>';
113
+ });
114
+ });
115
 
116
+ function resendEmail(scanId) {
117
+ fetch(`/api/email-report/${scanId}`)
118
+ .then(response => response.json())
119
+ .then(data => {
120
+ alert(data.message);
121
+ })
122
+ .catch(error => {
123
+ console.error('Error resending email:', error);
124
+ alert('Failed to resend report. Please try again.');
125
+ });
126
  }
127
 
128
+ document.getElementById('resend-email-btn')?.addEventListener('click', () => {
129
+ const scanId = document.getElementById('resend-email-btn').getAttribute('data-scan-id');
130
+ resendEmail(scanId);
131
+ });
 
 
 
 
132
  </script>
133
  </body>
134
  </html>