ma4389 commited on
Commit
96bc662
·
verified ·
1 Parent(s): 9a7810e

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +36 -0
  2. models.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing import image
5
+
6
+ # Load model
7
+ model = load_model("models.h5")
8
+
9
+ # Class labels
10
+ class_names = ['daisy', 'dandelion', 'rose', 'sunflower', 'tulip']
11
+
12
+ # Prediction function
13
+ def predict_flower(img):
14
+ img = img.resize((224, 224)) # Resize to match training input
15
+ img_array = image.img_to_array(img)
16
+ img_array = img_array / 255.0 # Normalize
17
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
18
+
19
+ predictions = model.predict(img_array)
20
+ class_index = np.argmax(predictions)
21
+ confidence = float(np.max(predictions))
22
+
23
+ return {class_names[i]: float(predictions[0][i]) for i in range(5)}
24
+
25
+ # Gradio interface
26
+ interface = gr.Interface(
27
+ fn=predict_flower,
28
+ inputs=gr.Image(type="pil"),
29
+ outputs=gr.Label(num_top_classes=5),
30
+ title="Flower Classifier",
31
+ description="Upload a flower image and the model will classify it as daisy, dandelion, rose, sunflower, or tulip.",
32
+ allow_flagging="never"
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ interface.launch()
models.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44389ef3fef2807d2904a13d693cc23f12c2177d4c4ad24254d902bdbc748b64
3
+ size 5222136
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ tensorflow
3
+ numpy
4
+ pillow