Files changed (3) hide show
  1. app.py +35 -0
  2. mpi_model.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+
6
+ # Modell laden
7
+ model = tf.keras.models.load_model("mpi_model.h5")
8
+
9
+ IMG_SIZE = (128, 128) # HIER: auf deine Trainingsgröße ändern
10
+ THRESHOLD = 0.5 # HIER: z.B. 0.21, wenn du das so willst
11
+
12
+ def predict_mpi(img: Image.Image):
13
+ # Preprocessing wie im Training!
14
+ img = img.resize(IMG_SIZE)
15
+ arr = np.array(img) / 255.0
16
+ if arr.ndim == 2: # falls Graustufen
17
+ arr = np.expand_dims(arr, axis=-1)
18
+ arr = np.expand_dims(arr, axis=0)
19
+
20
+ # Modellvorhersage
21
+ proba = float(model.predict(arr)[0][0]) # Sigmoid-Output 0..1 angenommen
22
+
23
+ label = "positiv" if proba >= THRESHOLD else "negativ"
24
+ return { "positiv": proba, "negativ": 1 - proba }
25
+
26
+ demo = gr.Interface(
27
+ fn=predict_mpi,
28
+ inputs=gr.Image(type="pil", label="MPI-Bild hochladen"),
29
+ outputs=gr.Label(num_top_classes=2, label="Wahrscheinlichkeiten"),
30
+ title="MPI Klassifikation",
31
+ description="Prototypisches KI-Tool zur Einschätzung von MPI-Bildern."
32
+ )
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch()
mpi_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29b0222de16209d9e4160d77bd77b9b9fa066df216dbd5f4a05bb72e8c7cd766
3
+ size 428784
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ tensorflow
3
+ numpy
4
+ Pillow