Spaces:
Sleeping
Sleeping
ariankhalfani
commited on
Commit
•
59adf16
1
Parent(s):
36b6162
Update app.py
Browse files
app.py
CHANGED
@@ -167,7 +167,7 @@ def submit_result(name, age, medical_record, sex, input_image, predicted_image,
|
|
167 |
conn.close()
|
168 |
return "Result submitted to database."
|
169 |
|
170 |
-
# Function to load and view database
|
171 |
def view_database():
|
172 |
conn = sqlite3.connect('results.db')
|
173 |
c = conn.cursor()
|
@@ -175,16 +175,17 @@ def view_database():
|
|
175 |
rows = c.fetchall()
|
176 |
conn.close()
|
177 |
|
178 |
-
# Prepare the
|
179 |
-
|
|
|
180 |
for row in rows:
|
181 |
name, age, medical_record, sex, input_image_bytes, predicted_image_bytes, result = row
|
182 |
-
|
183 |
# Decode the images
|
184 |
input_image = Image.open(BytesIO(input_image_bytes))
|
185 |
predicted_image = Image.open(BytesIO(predicted_image_bytes))
|
186 |
|
187 |
-
# Convert images to base64 for display
|
188 |
buffered_input = BytesIO()
|
189 |
input_image.save(buffered_input, format="PNG")
|
190 |
input_image_base64 = base64.b64encode(buffered_input.getvalue()).decode('utf-8')
|
@@ -193,13 +194,12 @@ def view_database():
|
|
193 |
predicted_image.save(buffered_predicted, format="PNG")
|
194 |
predicted_image_base64 = base64.b64encode(buffered_predicted.getvalue()).decode('utf-8')
|
195 |
|
196 |
-
#
|
197 |
-
|
198 |
|
199 |
-
|
200 |
-
df = pd.DataFrame(data, columns=["Name", "Age", "Medical Record", "Sex", "Input Image", "Predicted Image", "Result"])
|
201 |
|
202 |
-
return
|
203 |
|
204 |
# Function to download database or image
|
205 |
def download_file(choice):
|
@@ -232,10 +232,10 @@ def interface(name, age, medical_record, sex, input_image):
|
|
232 |
|
233 |
return output_image, raw_result, submit_status
|
234 |
|
235 |
-
# View Database Function
|
236 |
def view_db_interface():
|
237 |
-
|
238 |
-
return
|
239 |
|
240 |
# Download Function
|
241 |
def download_interface(choice):
|
@@ -272,7 +272,7 @@ with gr.Blocks() as demo:
|
|
272 |
|
273 |
with gr.Column():
|
274 |
view_db_btn = gr.Button("View Database")
|
275 |
-
db_output = gr.
|
276 |
|
277 |
view_db_btn.click(fn=view_db_interface, inputs=[], outputs=[db_output])
|
278 |
|
|
|
167 |
conn.close()
|
168 |
return "Result submitted to database."
|
169 |
|
170 |
+
# Function to load and view database in HTML format
|
171 |
def view_database():
|
172 |
conn = sqlite3.connect('results.db')
|
173 |
c = conn.cursor()
|
|
|
175 |
rows = c.fetchall()
|
176 |
conn.close()
|
177 |
|
178 |
+
# Prepare the HTML content
|
179 |
+
html_content = "<table border='1'><tr><th>Name</th><th>Age</th><th>Medical Record</th><th>Sex</th><th>Input Image</th><th>Predicted Image</th><th>Result</th></tr>"
|
180 |
+
|
181 |
for row in rows:
|
182 |
name, age, medical_record, sex, input_image_bytes, predicted_image_bytes, result = row
|
183 |
+
|
184 |
# Decode the images
|
185 |
input_image = Image.open(BytesIO(input_image_bytes))
|
186 |
predicted_image = Image.open(BytesIO(predicted_image_bytes))
|
187 |
|
188 |
+
# Convert images to base64 for display in HTML
|
189 |
buffered_input = BytesIO()
|
190 |
input_image.save(buffered_input, format="PNG")
|
191 |
input_image_base64 = base64.b64encode(buffered_input.getvalue()).decode('utf-8')
|
|
|
194 |
predicted_image.save(buffered_predicted, format="PNG")
|
195 |
predicted_image_base64 = base64.b64encode(buffered_predicted.getvalue()).decode('utf-8')
|
196 |
|
197 |
+
# Add a row to the HTML table
|
198 |
+
html_content += f"<tr><td>{name}</td><td>{age}</td><td>{medical_record}</td><td>{sex}</td><td><img src='data:image/png;base64,{input_image_base64}' width='100'></td><td><img src='data:image/png;base64,{predicted_image_base64}' width='100'></td><td>{result}</td></tr>"
|
199 |
|
200 |
+
html_content += "</table>"
|
|
|
201 |
|
202 |
+
return html_content
|
203 |
|
204 |
# Function to download database or image
|
205 |
def download_file(choice):
|
|
|
232 |
|
233 |
return output_image, raw_result, submit_status
|
234 |
|
235 |
+
# View Database Function (Updated)
|
236 |
def view_db_interface():
|
237 |
+
html_content = view_database()
|
238 |
+
return html_content
|
239 |
|
240 |
# Download Function
|
241 |
def download_interface(choice):
|
|
|
272 |
|
273 |
with gr.Column():
|
274 |
view_db_btn = gr.Button("View Database")
|
275 |
+
db_output = gr.HTML(label="Database Records")
|
276 |
|
277 |
view_db_btn.click(fn=view_db_interface, inputs=[], outputs=[db_output])
|
278 |
|