ariankhalfani commited on
Commit
749de3f
1 Parent(s): 274211c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -17
app.py CHANGED
@@ -223,20 +223,40 @@ def interface(name, age, medical_record, sex, input_image):
223
 
224
  return f'<img src="data:image/png;base64,{img_str}" alt="Processed Image"/>', raw_result, zip_file
225
 
226
- # Define Gradio interface
227
- gr.Interface(
228
- fn=interface,
229
- inputs=[
230
- gr.Textbox(label="Name"),
231
- gr.Textbox(label="Age"),
232
- gr.Textbox(label="Medical Record"),
233
- gr.Dropdown(label="Sex", choices=["Male", "Female", "Other"]),
234
- gr.Image(source="upload", tool="editor", label="Upload an Image")
235
- ],
236
- outputs=[
237
- gr.HTML(label="Processed Image"),
238
- gr.Textbox(label="Raw Predictions"),
239
- gr.File(label="Download ZIP")
240
- ],
241
- title="Patient Image Analysis"
242
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
 
224
  return f'<img src="data:image/png;base64,{img_str}" alt="Processed Image"/>', raw_result, zip_file
225
 
226
+ with gr.Blocks() as demo:
227
+ with gr.Column():
228
+ gr.Markdown("# Cataract Detection System")
229
+ gr.Markdown("Upload an image to detect cataract and add patient details.")
230
+ gr.Markdown("This application uses YOLOv8 with mAP=0.981")
231
+
232
+ with gr.Column():
233
+ name = gr.Textbox(label="Name")
234
+ age = gr.Number(label="Age")
235
+ medical_record = gr.Number(label="Medical Record")
236
+ sex = gr.Radio(["Male", "Female"], label="Sex")
237
+ input_image = gr.Image(type="pil", label="Upload an Image", image_mode="RGB")
238
+
239
+ with gr.Column():
240
+ submit_btn = gr.Button("Submit")
241
+ output_image = gr.Image(type="pil", label="Predicted Image")
242
+
243
+ with gr.Row():
244
+ raw_result = gr.Textbox(label="Prediction Result")
245
+
246
+ with gr.Row():
247
+ download_html_btn = gr.Button("Download Patient Information (HTML)")
248
+ download_uploaded_btn = gr.Button("Download Uploaded Images")
249
+ download_predicted_btn = gr.Button("Download Predicted Images")
250
+
251
+ # Add file download output components for the uploaded and predicted images
252
+ patient_info_file = gr.File(label="Patient Information HTML File")
253
+ uploaded_folder_file = gr.File(label="Uploaded Images Zip File")
254
+ predicted_folder_file = gr.File(label="Predicted Images Zip File")
255
+
256
+ submit_btn.click(fn=interface, inputs=[name, age, medical_record, sex, input_image], outputs=[output_image, raw_result])
257
+ download_html_btn.click(fn=save_patient_info_to_html, inputs=[name, age, medical_record, sex, raw_result], outputs=patient_info_file)
258
+ download_uploaded_btn.click(fn=download_uploaded_folder, outputs=uploaded_folder_file)
259
+ download_predicted_btn.click(fn=download_predicted_folder, outputs=predicted_folder_file)
260
+
261
+ # Launch Gradio app
262
+ demo.launch()