ftx7go commited on
Commit
cabae73
·
verified ·
1 Parent(s): 819753a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -18,6 +18,9 @@ model = tf.keras.models.load_model("my_keras_model.h5")
18
  with open("templates/re.html", "r", encoding="utf-8") as file:
19
  html_content = file.read()
20
 
 
 
 
21
  # Function to process X-ray and generate a PDF report
22
  def generate_report(name, age, gender, weight, height, allergies, cause, xray):
23
  image_size = (224, 224)
@@ -35,7 +38,7 @@ def generate_report(name, age, gender, weight, height, allergies, cause, xray):
35
 
36
  # Injury severity classification
37
  severity = "Mild" if prediction < 0.3 else "Moderate" if prediction < 0.7 else "Severe"
38
-
39
  # Treatment details table
40
  treatment_data = [
41
  ["Severity Level", "Recommended Treatment", "Recovery Duration"],
@@ -114,6 +117,10 @@ def generate_report(name, age, gender, weight, height, allergies, cause, xray):
114
 
115
  return report_path # Return path for auto-download
116
 
 
 
 
 
117
  # Define Gradio Interface
118
  with gr.Blocks() as app:
119
  gr.HTML(html_content) # Display `re.html` content in Gradio
@@ -134,10 +141,16 @@ with gr.Blocks() as app:
134
 
135
  with gr.Row():
136
  xray = gr.Image(type="filepath", label="Upload X-ray Image")
 
 
 
 
137
 
138
  submit_button = gr.Button("Generate Report")
139
  output_file = gr.File(label="Download Report")
140
 
 
 
141
  submit_button.click(
142
  generate_report,
143
  inputs=[name, age, gender, weight, height, allergies, cause, xray],
 
18
  with open("templates/re.html", "r", encoding="utf-8") as file:
19
  html_content = file.read()
20
 
21
+ # List of sample images
22
+ sample_images = [f"samples/{img}" for img in os.listdir("samples") if img.endswith((".png", ".jpg", ".jpeg"))]
23
+
24
  # Function to process X-ray and generate a PDF report
25
  def generate_report(name, age, gender, weight, height, allergies, cause, xray):
26
  image_size = (224, 224)
 
38
 
39
  # Injury severity classification
40
  severity = "Mild" if prediction < 0.3 else "Moderate" if prediction < 0.7 else "Severe"
41
+
42
  # Treatment details table
43
  treatment_data = [
44
  ["Severity Level", "Recommended Treatment", "Recovery Duration"],
 
117
 
118
  return report_path # Return path for auto-download
119
 
120
+ # Function to select a sample image
121
+ def use_sample_image(sample_image_path):
122
+ return sample_image_path # Returns selected sample image filepath
123
+
124
  # Define Gradio Interface
125
  with gr.Blocks() as app:
126
  gr.HTML(html_content) # Display `re.html` content in Gradio
 
141
 
142
  with gr.Row():
143
  xray = gr.Image(type="filepath", label="Upload X-ray Image")
144
+
145
+ with gr.Row():
146
+ sample_selector = gr.Dropdown(choices=sample_images, label="Use Sample Image")
147
+ select_button = gr.Button("Load Sample Image")
148
 
149
  submit_button = gr.Button("Generate Report")
150
  output_file = gr.File(label="Download Report")
151
 
152
+ select_button.click(use_sample_image, inputs=[sample_selector], outputs=[xray])
153
+
154
  submit_button.click(
155
  generate_report,
156
  inputs=[name, age, gender, weight, height, allergies, cause, xray],