pfrei commited on
Commit
761d5f6
·
verified ·
1 Parent(s): d636acf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -32
app.py CHANGED
@@ -1,32 +1,32 @@
1
- import gradio as gr
2
- import tensorflow as tf
3
- from PIL import Image
4
- import numpy as np
5
-
6
- # Load your custom regression model
7
- model_path = "Doggos.keras"
8
- model = tf.keras.models.load_model(model_path)
9
-
10
- labels = ['Bedlington_terrier', 'Bernese_mountain_dog', 'Dandie_Dinmont', 'Gordon_setter', 'Ibizan_hound', 'Norwegian_elkhound'] # corrected labels list
11
-
12
- # Define regression function
13
- def predict_regression(image):
14
- # Preprocess image
15
- image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
16
- image = image.resize((150, 150)).convert('RGB') # Resize the image to 150x150 and convert to RGB
17
- image = np.array(image)
18
- print(image.shape)
19
- # Predict
20
- prediction = model.predict(image[None, ...]) # Assuming single regression value
21
- confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
22
- return confidences
23
-
24
- # Create Gradio interface
25
- input_image = gr.Image()
26
- output_text = gr.Textbox(label="Predicted Value")
27
- interface = gr.Interface(fn=predict_regression,
28
- inputs=input_image,
29
- outputs=gr.Label(),
30
- examples=["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg"],
31
- description="A simple MLP classification model for image classification using the dog breed dataset.")
32
- interface.launch()
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load your custom regression model
7
+ model_path = "Doggos.keras"
8
+ model = tf.keras.models.load_model(model_path)
9
+
10
+ labels = ['Bedlington_terrier', 'Bernese_mountain_dog', 'Dandie_Dinmont', 'Gordon_setter', 'Ibizan_hound', 'Norwegian_elkhound'] # corrected labels list
11
+
12
+ # Define regression function
13
+ def predict_regression(image):
14
+ # Preprocess image
15
+ image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
16
+ image = image.resize((150, 150)).convert('RGB') # Resize the image to 150x150 and convert to RGB
17
+ image = np.array(image)
18
+ print(image.shape)
19
+ # Predict
20
+ prediction = model.predict(image[None, ...]) # Assuming single regression value
21
+ confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
22
+ return confidences
23
+
24
+ # Create Gradio interface
25
+ input_image = gr.Image()
26
+ output_text = gr.Textbox(label="Predicted Value")
27
+ interface = gr.Interface(fn=predict_regression,
28
+ inputs=input_image,
29
+ outputs=gr.Label(),
30
+ examples=["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg"],
31
+ description="Wer ist ein guter Junge? Du bist ein aber ganz feiner und braver Junge! hechel hechel hechel :)")
32
+ interface.launch()