foreversheikh commited on
Commit
c5b5003
·
verified ·
1 Parent(s): 3bbf8e2

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +77 -0
  3. model_n.keras +3 -0
  4. requirements.txt +6 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model_n.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow.keras.models import load_model
5
+ from PIL import Image
6
+ import cv2
7
+
8
+ # Load the model
9
+ model = tf.keras.models.load_model("model_n.keras")
10
+
11
+ # Define class names
12
+ class_names = [
13
+ 'Bush Clock Vine', 'Common Lanthana', 'Datura', 'Hibiscus', 'Jatropha', 'Marigold',
14
+ 'Nityakalyani', 'Rose', 'Yellow_Daisy', 'adathoda', 'banana', 'champaka', 'chitrak',
15
+ 'crown flower', "four o'clock flower", 'honeysuckle', 'indian mallow', 'malabar melastome',
16
+ 'nagapoovu', 'pinwheel flower', 'shankupushpam', 'spider lily', 'sunflower', 'thechi',
17
+ 'thumba', 'touch me not', 'tridax procumbens', 'wild_potato_vine'
18
+ ]
19
+
20
+ # Title
21
+ st.title("Flower Identifier")
22
+
23
+ # Choose mode
24
+ mode = st.radio("Choose input method:", ["Upload Image", "Real-Time Camera"])
25
+
26
+ if mode == "Upload Image":
27
+ st.markdown("### Upload an image of a flower")
28
+ img = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
29
+
30
+ if img is not None:
31
+ st.image(img, caption="Uploaded Image", use_column_width=True)
32
+
33
+ image = Image.open(img).convert("RGB")
34
+ image = tf.keras.preprocessing.image.img_to_array(image)
35
+ image = tf.cast(image, tf.float32)
36
+ image = tf.expand_dims(image, 0)
37
+
38
+ if st.button("Identify Flower"):
39
+ prediction = model.predict(image)
40
+ predicted_class = np.argmax(prediction[0])
41
+ confidence = round(100 * np.max(prediction[0]), 2)
42
+ flower_name = class_names[predicted_class]
43
+
44
+ st.success(f"Predicted Flower: **{flower_name}**")
45
+ st.info(f"Confidence: **{confidence}%**")
46
+
47
+ elif mode == "Real-Time Camera":
48
+ st.markdown("### Real-Time Flower Recognition")
49
+ run = st.checkbox('Start Camera')
50
+ FRAME_WINDOW = st.image([])
51
+
52
+ cap = None
53
+ if run:
54
+ cap = cv2.VideoCapture(0)
55
+ while run:
56
+ ret, frame = cap.read()
57
+ if not ret:
58
+ st.warning("Failed to access camera.")
59
+ break
60
+
61
+ img_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
62
+ img_array = tf.keras.preprocessing.image.img_to_array(img_rgb)
63
+ img_array = tf.expand_dims(tf.cast(img_array, tf.float32), 0)
64
+
65
+ predictions = model.predict(img_array)
66
+ predicted_class = np.argmax(predictions[0])
67
+ confidence = round(100 * np.max(predictions[0]), 2)
68
+ flower_name = class_names[predicted_class]
69
+
70
+ # Annotate frame
71
+ cv2.putText(frame, f"{flower_name} ({confidence}%)", (10, 30),
72
+ cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
73
+
74
+ FRAME_WINDOW.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
75
+
76
+ if cap:
77
+ cap.release()
model_n.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4981c52739db96f17a22ed4e37faa78e62ddda5bf49f0309dd2eb43039d5685
3
+ size 2308223
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit>=1.30.0
2
+ numpy>=1.22.0
3
+ tensorflow>=2.19.0
4
+ Pillow>=9.0.0
5
+ opencv-python>=4.5.5
6
+ keras