Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,34 +4,44 @@ from PIL import Image
|
|
4 |
import numpy as np
|
5 |
|
6 |
|
7 |
-
# Laden Sie Ihr benutzerdefiniertes Regressionsmodell
|
8 |
-
model = tf.keras.models.load_model('Task_Pokemon.keras')
|
9 |
-
|
10 |
# Klassennamen, sollten Ihrem Dataset entsprechen
|
11 |
-
class_names = ['
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
img_array = tf.expand_dims(img_array, 0) # Erstelle einen Batch
|
18 |
-
predictions = model.predict(img_array)
|
19 |
-
predicted_class = class_names[np.argmax(predictions[0])]
|
20 |
-
confidence = np.max(predictions[0])
|
21 |
-
return {predicted_class: float(confidence)}
|
22 |
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
iface = gr.Interface(
|
28 |
-
fn=
|
29 |
-
inputs=
|
30 |
-
outputs=
|
31 |
-
title=
|
32 |
-
description=
|
|
|
33 |
)
|
34 |
-
|
35 |
iface.launch()
|
36 |
|
37 |
|
|
|
4 |
import numpy as np
|
5 |
|
6 |
|
|
|
|
|
|
|
7 |
# Klassennamen, sollten Ihrem Dataset entsprechen
|
8 |
+
class_names = ['Apple__black_rot', 'Apple__healthy', 'Apple__rust', 'Apple__scab']
|
9 |
+
|
10 |
+
def predict_figure(uploaded_file):
|
11 |
+
if uploaded_file is None:
|
12 |
+
return "No file uploaded.", None, "No prediction"
|
13 |
+
|
14 |
+
model = tf.keras.models.load_model('apple_classification.keras')
|
15 |
|
16 |
+
# Load the image from the file path
|
17 |
+
with Image.open(uploaded_file).convert('RGB') as img:
|
18 |
+
img = img.resize((150, 150))
|
19 |
+
img_array = np.array(img)
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
prediction = model.predict(np.expand_dims(img_array, axis=0))
|
22 |
|
23 |
+
# Identify the most confident prediction
|
24 |
+
confidences = {class_names[i]: np.round(float(prediction[0][i]), 2) for i in range(len(class_names))}
|
25 |
+
return img, confidences
|
26 |
|
27 |
+
# Define example images
|
28 |
+
examples = [
|
29 |
+
["images/Apple__black_rot.jpg"],
|
30 |
+
["images/Apple__healthy.png"],
|
31 |
+
["images/Apple__rust.png"],
|
32 |
+
["images/Apple__scab.png"]
|
33 |
+
]
|
34 |
+
|
35 |
+
|
36 |
+
# Define the Gradio interface
|
37 |
iface = gr.Interface(
|
38 |
+
fn=predict_figure, # Function to process the input
|
39 |
+
inputs=gr.File(label="Upload File"), # File upload widget
|
40 |
+
outputs=["image", "text"], # Output types for image and text
|
41 |
+
title="Leaf Disease Classifier", # Title of the interface
|
42 |
+
description="Upload a picture of a Apple Leaf to see condition health it is and the model's confidence level.", # Description of the interface
|
43 |
+
examples=examples # Example images
|
44 |
)
|
|
|
45 |
iface.launch()
|
46 |
|
47 |
|