ariankhalfani commited on
Commit
64a8807
1 Parent(s): e929535

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -30
app.py CHANGED
@@ -4,8 +4,6 @@ import cv2
4
  import numpy as np
5
  from PIL import Image, ImageDraw, ImageFont
6
  import sqlite3
7
- import base64
8
- from io import BytesIO
9
  import tempfile
10
  import pandas as pd
11
 
@@ -226,40 +224,38 @@ def download_interface(choice):
226
  try:
227
  file_path = download_file(choice)
228
  with open(file_path, "rb") as file:
229
- return file.read(), f"{choice}"
230
  except Exception as e:
231
- return str(e)
232
 
233
- with gr.Blocks() as demo:
234
- with gr.Tabs():
235
- with gr.Tab("Image Analyzer and Screener"):
236
- gr.Markdown("## Cataract Detection System")
237
- with gr.Row():
238
- with gr.Column():
239
- input_image = gr.Image(label="Upload Image")
240
- name = gr.Textbox(label="Patient Name")
241
- patient_id = gr.Textbox(label="Patient ID")
242
- submit_btn = gr.Button("Submit")
243
-
244
- with gr.Column():
245
- output_image = gr.Image(label="Predicted Image")
246
- raw_result = gr.Textbox(label="Raw Result")
247
- submit_status = gr.Textbox(label="Submission Status")
248
 
249
- submit_btn.click(fn=interface, inputs=[name, patient_id, input_image], outputs=[output_image, raw_result, submit_status])
 
250
 
251
- with gr.Tab("Database Viewer"):
252
- view_db_btn = gr.Button("View Database")
253
- database_display = gr.Dataframe()
 
 
254
 
255
- view_db_btn.click(fn=view_db_interface, outputs=database_display)
 
 
256
 
257
- with gr.Tab("Download Results"):
258
- download_choice = gr.Radio(["Database (.db)", "Predicted Image (.png)"], label="Download Option")
259
- download_btn = gr.Button("Download")
 
260
 
261
- download_output = gr.File()
 
262
 
263
- download_btn.click(fn=download_interface, inputs=download_choice, outputs=download_output)
 
 
 
264
 
265
- demo.launch()
 
 
4
  import numpy as np
5
  from PIL import Image, ImageDraw, ImageFont
6
  import sqlite3
 
 
7
  import tempfile
8
  import pandas as pd
9
 
 
224
  try:
225
  file_path = download_file(choice)
226
  with open(file_path, "rb") as file:
227
+ return file.read(), file_path
228
  except Exception as e:
229
+ return f"Error: {str(e)}", None
230
 
231
+ # Build Gradio Interface
232
+ app = gr.Blocks()
 
 
 
 
 
 
 
 
 
 
 
 
 
233
 
234
+ with app:
235
+ gr.Markdown("# Eye Condition Detection System")
236
 
237
+ with gr.Row():
238
+ with gr.Column():
239
+ name = gr.Textbox(label="Name", placeholder="Enter patient's name")
240
+ patient_id = gr.Textbox(label="Patient ID", placeholder="Enter patient ID")
241
+ input_image = gr.Image(source="upload", type="pil", label="Upload an Eye Image")
242
 
243
+ with gr.Row():
244
+ download_choice = gr.Radio(label="Download Choice", choices=["Database (.db)", "Last Predicted Image (.png)"], value="Database (.db)")
245
+ download_button = gr.Button("Download")
246
 
247
+ with gr.Column():
248
+ predicted_image = gr.Image(label="Predicted Image")
249
+ raw_result = gr.Textbox(label="Raw Prediction Results", interactive=False)
250
+ submit_status = gr.Textbox(label="Submission Status", interactive=False)
251
 
252
+ predict_button = gr.Button("Predict")
253
+ view_db_button = gr.Button("View Database")
254
 
255
+ # Button actions
256
+ predict_button.click(interface, inputs=[name, patient_id, input_image], outputs=[predicted_image, raw_result, submit_status])
257
+ view_db_button.click(view_db_interface, outputs=gr.Dataframe())
258
+ download_button.click(download_interface, inputs=[download_choice], outputs=[gr.File(), gr.Textbox()])
259
 
260
+ # Launch the Gradio app
261
+ app.launch()