ftx7go commited on
Commit
75ae599
·
verified ·
1 Parent(s): 12a86ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
@@ -5,7 +8,6 @@ from tensorflow.keras.preprocessing import image
5
  from PIL import Image
6
  from reportlab.lib.pagesizes import letter
7
  from reportlab.pdfgen import canvas
8
- import os
9
 
10
  # Load the trained model
11
  model = tf.keras.models.load_model("my_keras_model.h5")
@@ -14,8 +16,8 @@ model = tf.keras.models.load_model("my_keras_model.h5")
14
  def generate_report(name, age, gender, xray1, xray2):
15
  image_size = (224, 224)
16
 
17
- def predict_fracture(xray):
18
- img = Image.open(xray).resize(image_size)
19
  img_array = image.img_to_array(img) / 255.0
20
  img_array = np.expand_dims(img_array, axis=0)
21
  prediction = model.predict(img_array)[0][0]
@@ -60,8 +62,8 @@ interface = gr.Interface(
60
  gr.Textbox(label="Patient Name"),
61
  gr.Number(label="Age"),
62
  gr.Radio(["Male", "Female", "Other"], label="Gender"),
63
- gr.Image(type="file", label="Upload X-ray Image 1"),
64
- gr.Image(type="file", label="Upload X-ray Image 2"),
65
  ],
66
  outputs=gr.File(label="Download Report"),
67
  title="Bone Fracture Detection & Medical Report",
 
1
+ import os
2
+ os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Force TensorFlow to use CPU
3
+
4
  import gradio as gr
5
  import tensorflow as tf
6
  import numpy as np
 
8
  from PIL import Image
9
  from reportlab.lib.pagesizes import letter
10
  from reportlab.pdfgen import canvas
 
11
 
12
  # Load the trained model
13
  model = tf.keras.models.load_model("my_keras_model.h5")
 
16
  def generate_report(name, age, gender, xray1, xray2):
17
  image_size = (224, 224)
18
 
19
+ def predict_fracture(xray_path):
20
+ img = Image.open(xray_path).resize(image_size)
21
  img_array = image.img_to_array(img) / 255.0
22
  img_array = np.expand_dims(img_array, axis=0)
23
  prediction = model.predict(img_array)[0][0]
 
62
  gr.Textbox(label="Patient Name"),
63
  gr.Number(label="Age"),
64
  gr.Radio(["Male", "Female", "Other"], label="Gender"),
65
+ gr.Image(type="filepath", label="Upload X-ray Image 1"),
66
+ gr.Image(type="filepath", label="Upload X-ray Image 2"),
67
  ],
68
  outputs=gr.File(label="Download Report"),
69
  title="Bone Fracture Detection & Medical Report",