MuhammmadRizwanRizwan commited on
Commit
df1d7ff
·
verified ·
1 Parent(s): 8bc4cb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -7
app.py CHANGED
@@ -1,11 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- # Set title of the app
4
- st.title("Simple Streamlit App")
5
 
6
- # Add text input
7
- user_input = st.text_input("Enter your name:")
 
8
 
9
- # Display the input value
10
- if user_input:
11
- st.write(f"Hello, {user_input}!")
 
1
+ # import streamlit as st
2
+
3
+ # # Set title of the app
4
+ # st.title("Simple Streamlit App")
5
+
6
+ # # Add text input
7
+ # user_input = st.text_input("Enter your name:")
8
+
9
+ # # Display the input value
10
+ # if user_input:
11
+ # st.write(f"Hello, {user_input}!")
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
  import streamlit as st
20
+ from tensorflow.keras.models import load_model
21
+ from tensorflow.keras.preprocessing import image
22
+ import numpy as np
23
+ from PIL import Image
24
+
25
+ # Load the pre-trained models
26
+ @st.cache_resource
27
+ def load_models():
28
+ model1 = load_model('name_model_inception.h5') # Update with your Hugging Face model path
29
+ model2 = load_model('type_model_inception.h5') # Update with your Hugging Face model path
30
+ return model1, model2
31
+
32
+ model1, model2 = load_models()
33
+
34
+ # Label mappings
35
+ label_map1 = {
36
+ 0: "Banana", 1: "Cucumber", 2: "Grape", 3: "Kaki", 4: "Papaya",
37
+ 5: "Peach", 6: "Pear", 7: "Pepper", 8: "Strawberry", 9: "Watermelon", 10: "Tomato"
38
+ }
39
+
40
+ label_map2 = {
41
+ 0: "Good", 1: "Mild", 2: "Rotten"
42
+ }
43
+
44
+ # Streamlit app layout
45
+ st.title("Fruit Classifier")
46
+
47
+ # Upload image
48
+ uploaded_file = st.file_uploader("Choose an image of a fruit", type=["jpg", "jpeg", "png"])
49
+
50
+ if uploaded_file is not None:
51
+ # Display the uploaded image
52
+ img = Image.open(uploaded_file)
53
+ st.image(img, caption="Uploaded Image", use_column_width=True)
54
+
55
+ # Preprocess the image
56
+ img = img.resize((224, 224)) # Resize image to match the model input
57
+ img_array = image.img_to_array(img)
58
+ img_array = np.expand_dims(img_array, axis=0)
59
+ img_array = img_array / 255.0 # Normalize the image
60
+
61
+ # Make predictions
62
+ pred1 = model1.predict(img_array)
63
+ pred2 = model2.predict(img_array)
64
 
65
+ predicted_class1 = np.argmax(pred1, axis=1)
66
+ predicted_class2 = np.argmax(pred2, axis=1)
67
 
68
+ # Display results
69
+ st.write(f"**Type Detection**: {label_map1[predicted_class1[0]]}")
70
+ st.write(f"**Condition Detection**: {label_map2[predicted_class2[0]]}")
71