osamaifti commited on
Commit
dd4ebba
·
1 Parent(s): bad20b8

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -53
app.py DELETED
@@ -1,53 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """Bird_Species_Interface.ipynb
3
-
4
- Automatically generated by Colaboratory.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1phGfuDAxvDjzxX7jYYCg92VjPhua9u1_
8
- """
9
-
10
-
11
-
12
- import gradio as gr
13
- import numpy as np
14
- import tensorflow_hub as hub
15
- import tensorflow as tf
16
- from tensorflow.keras.models import load_model
17
- import cv2
18
-
19
- import gradio as gr
20
- import tensorflow as tf
21
- import cv2
22
-
23
- # Define a dictionary to map the custom layer to its implementation
24
- custom_objects = {'KerasLayer': hub.KerasLayer}
25
-
26
- # Load your model (ensure the path is correct) and provide the custom_objects dictionary
27
- model = tf.keras.models.load_model('model.h5', custom_objects=custom_objects)
28
-
29
- # Define a function to preprocess the image
30
- def preprocess_image(image):
31
- img = cv2.resize(image, (224, 224))
32
- img = img / 255.0 # Normalize pixel values to [0, 1]
33
- return img
34
-
35
- # Define the prediction function
36
- def predict_image(image):
37
- img = preprocess_image(image)
38
- img = img[np.newaxis, ...] # Add batch dimension
39
- prediction = model.predict(img)
40
- predicted_class = tf.argmax(prediction, axis=1).numpy()[0]
41
- confidence = tf.reduce_max(prediction).numpy()
42
- return f"Class: {predicted_class}, Confidence: {confidence:.4f}"
43
-
44
- # Define Gradio interface
45
- input_image = gr.inputs.Image(shape=(224, 224))
46
- output_label = gr.outputs.Label()
47
-
48
- gr.Interface(
49
- fn=predict_image,
50
- inputs=input_image,
51
- outputs=output_label,
52
- live=True
53
- ).launch()