zhawszenthen commited on
Commit
82380de
1 Parent(s): 5c4a90a

update app

Browse files
Files changed (1) hide show
  1. app.py +10 -25
app.py CHANGED
@@ -10,38 +10,23 @@ model = tf.keras.models.load_model(model_path)
10
  # Klassenlabels
11
  labels = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor']
12
 
13
- # Bildvorverarbeitung
14
- def preprocess_image(image):
15
- image = Image.fromarray(image.astype('uint8')) # Konvertierung des Numpy-Arrays in ein PIL-Bild
16
- image = image.resize((224, 224)) # Bildgröße anpassen auf 224x224 Pixel
17
- image = np.array(image) / 255 - 1.0 # In Float konvertieren und normalisieren auf [-1, 1]
18
-
19
- # Sicherstellen, dass das Bild 3 Farbkanäle hat
20
- if image.ndim == 2: # Wenn das Bild grau ist, in RGB konvertieren
21
- image = np.stack((image,)*3, axis=-1)
22
-
23
- return image
24
-
25
- # Vorhersagefunktion
26
  def predict_image(image):
27
- image = preprocess_image(image) # Verwende die aktualisierte Vorverarbeitung
 
 
28
 
29
- # Vorhersage
30
- prediction = model.predict(image[None, ...]) # Batch-Dimension hinzufügen
31
  confidences = {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
32
  return confidences
33
 
34
- # Gradio-Interface
35
- input_image = gr.Image()
36
- output_text = gr.Textbox(label="Predicted Value")
37
-
38
  iface = gr.Interface(
39
  fn=predict_image,
40
- inputs=input_image,
41
- outputs=gr.Label(),
42
- title="Brain Tumor Classification",
43
- description="Please upload an image of your MRI brain scan. The model will classify if you've got a tumor or not. Who needs a radiologist anyway?"
 
44
  )
45
 
46
- # Starten der Gradio-Oberfläche
47
  iface.launch(share=True)
 
10
  # Klassenlabels
11
  labels = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor']
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def predict_image(image):
14
+ image = Image.fromarray(image.astype('uint8'), 'RGB')
15
+ image = image.resize((64, 64))
16
+ image = np.array(image)
17
 
18
+ prediction = model.predict(np.expand_dims(image, axis=0))
 
19
  confidences = {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
20
  return confidences
21
 
22
+ # Gradio interface
 
 
 
23
  iface = gr.Interface(
24
  fn=predict_image,
25
+ inputs=gr.Image(),
26
+ outputs=gr.Label(num_top_classes=10),
27
+ title="Sentinel Image Classifier",
28
+ description="Upload your MRI image and the model will predict, if there's a tumor present"
29
+
30
  )
31
 
 
32
  iface.launch(share=True)