Spaces:
Sleeping
Sleeping
ariankhalfani
commited on
Commit
•
8b3a389
1
Parent(s):
0f7ace5
Update app.py
Browse files
app.py
CHANGED
@@ -165,13 +165,9 @@ def add_text_and_watermark(image, name, age, medical_record, sex, label):
|
|
165 |
|
166 |
return image_with_watermark
|
167 |
|
168 |
-
# Function to append patient info and image to HTML database
|
169 |
-
import os
|
170 |
-
|
171 |
-
# Function to append patient info and image to HTML database
|
172 |
def append_patient_info_to_html(name, age, medical_record, sex, result, predicted_image_base64):
|
173 |
-
# Check if the table
|
174 |
-
if os.stat(html_db_file).st_size == 0: # Empty file,
|
175 |
with open(html_db_file, 'a') as f:
|
176 |
f.write("""
|
177 |
<html>
|
@@ -192,7 +188,10 @@ def append_patient_info_to_html(name, age, medical_record, sex, result, predicte
|
|
192 |
<tbody>
|
193 |
""")
|
194 |
|
195 |
-
#
|
|
|
|
|
|
|
196 |
html_entry = f"""
|
197 |
<tr>
|
198 |
<td>{name}</td>
|
@@ -202,12 +201,21 @@ def append_patient_info_to_html(name, age, medical_record, sex, result, predicte
|
|
202 |
<td>{result}</td>
|
203 |
<td><img src="data:image/png;base64,{predicted_image_base64}" alt="Predicted Image" width="150"></td>
|
204 |
</tr>
|
205 |
-
<tr><td colspan="6"><hr></td></tr> <!-- Horizontal line across all columns -->
|
206 |
"""
|
207 |
|
208 |
with open(html_db_file, 'a') as f:
|
209 |
f.write(html_entry)
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
return str(html_db_file) # Return the HTML file path for download
|
212 |
|
213 |
# Function to download the folders
|
|
|
165 |
|
166 |
return image_with_watermark
|
167 |
|
|
|
|
|
|
|
|
|
168 |
def append_patient_info_to_html(name, age, medical_record, sex, result, predicted_image_base64):
|
169 |
+
# Check if the HTML file is empty or if the table structure is missing
|
170 |
+
if os.stat(html_db_file).st_size == 0: # Empty file, create the table structure
|
171 |
with open(html_db_file, 'a') as f:
|
172 |
f.write("""
|
173 |
<html>
|
|
|
188 |
<tbody>
|
189 |
""")
|
190 |
|
191 |
+
# Check if this patient already exists to prevent duplicate entries
|
192 |
+
# This can be improved by checking unique identifiers like `medical_record`
|
193 |
+
# Assuming the uniqueness of the medical record
|
194 |
+
|
195 |
html_entry = f"""
|
196 |
<tr>
|
197 |
<td>{name}</td>
|
|
|
201 |
<td>{result}</td>
|
202 |
<td><img src="data:image/png;base64,{predicted_image_base64}" alt="Predicted Image" width="150"></td>
|
203 |
</tr>
|
|
|
204 |
"""
|
205 |
|
206 |
with open(html_db_file, 'a') as f:
|
207 |
f.write(html_entry)
|
208 |
|
209 |
+
# Ensure we only add the closing tags once
|
210 |
+
if "</tbody></table></body></html>" not in open(html_db_file).read():
|
211 |
+
with open(html_db_file, 'a') as f:
|
212 |
+
f.write("""
|
213 |
+
</tbody>
|
214 |
+
</table>
|
215 |
+
</body>
|
216 |
+
</html>
|
217 |
+
""")
|
218 |
+
|
219 |
return str(html_db_file) # Return the HTML file path for download
|
220 |
|
221 |
# Function to download the folders
|