Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +30 -0
- model.h5 +3 -0
- requirements.txt +18 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import numpy as np
|
4 |
+
from tensorflow.keras.preprocessing import image as keras_image
|
5 |
+
from tensorflow.keras.applications.resnet50 import preprocess_input
|
6 |
+
from tensorflow.keras.models import load_model
|
7 |
+
|
8 |
+
# Load your trained modelC:\Daten\Studium Wirtsc
|
9 |
+
model = load_model('C:\Users\kavi1\OneDrive\Desktop\Studium\Hauptstudium\Semester 3\KIA\Mündliche Prüfung\ImageClassification\model.h5') # Ensure this path is correct
|
10 |
+
|
11 |
+
def predict_teigwaren(img):
|
12 |
+
img = Image.fromarray(img.astype('uint8'), 'RGB') # Ensure the image is in RGB
|
13 |
+
img = img.resize((224, 224)) # Resize the image properly using PIL
|
14 |
+
img_array = keras_image.img_to_array(img) # Convert the image to an array
|
15 |
+
img_array = np.expand_dims(img_array, axis=0) # Expand dimensions to fit model input
|
16 |
+
img_array = preprocess_input(img_array) # Preprocess the input as expected by ResNet50
|
17 |
+
|
18 |
+
prediction = model.predict(img_array) # Predict using the model
|
19 |
+
classes = ['Mafaldine', 'Spaghetti', 'Tagliatelle' ] # Specific Teigwaren names
|
20 |
+
return {classes[i]: float(prediction[0][i]) for i in range(3)} # Return the prediction
|
21 |
+
|
22 |
+
# Define Gradio interface
|
23 |
+
interface = gr.Interface(fn=predict_teigwaren,
|
24 |
+
inputs="image", # Simplified input type
|
25 |
+
outputs="label", # Simplified output type
|
26 |
+
title="Teigwaren Classifier",
|
27 |
+
description="Lade ein Bild von einer Teigwarensorte hoch und lass den KI-Algorithmus die Sorte bestimmen.")
|
28 |
+
|
29 |
+
# Launch the interface
|
30 |
+
interface.launch()
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ea05958bf19a0d284bfa3004a50cf13c2d11c828606d48d0f45cbe0bb08a04bd
|
3 |
+
size 308621848
|
requirements.txt
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
blinker==1.7.0
|
2 |
+
click==8.1.7
|
3 |
+
Flask==3.0.2
|
4 |
+
Flask-Cors==4.0.0
|
5 |
+
itsdangerous==2.1.2
|
6 |
+
Jinja2==3.1.3
|
7 |
+
joblib==1.3.2
|
8 |
+
MarkupSafe==2.1.5
|
9 |
+
numpy==1.26.4
|
10 |
+
pandas==2.2.1
|
11 |
+
python-dateutil==2.8.2
|
12 |
+
pytz==2024.1
|
13 |
+
scikit-learn==1.4.1.post1
|
14 |
+
scipy==1.12.0
|
15 |
+
six==1.16.0
|
16 |
+
threadpoolctl==3.3.0
|
17 |
+
tzdata==2024.1
|
18 |
+
Werkzeug==3.0.1
|