DataWizard9742 commited on
Commit
a247dde
·
1 Parent(s): f349631

Create app

Browse files
Files changed (1) hide show
  1. app +35 -0
app ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.applications import MobileNet
4
+ from tensorflow.keras.applications.mobilenet import preprocess_input, decode_predictions
5
+ from tensorflow.keras.preprocessing import image
6
+ import numpy as np
7
+
8
+ # Load the pre-trained MobileNet model
9
+ model = MobileNet(weights='imagenet')
10
+
11
+ # Create a Streamlit web app
12
+ st.title("Image Classification with MobileNet")
13
+
14
+ # Upload an image through Streamlit
15
+ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
16
+
17
+ if uploaded_image is not None:
18
+ # Display the uploaded image
19
+ st.image(uploaded_image, caption='Uploaded Image', use_column_width=True)
20
+
21
+ # Preprocess the image for MobileNet
22
+ img = image.load_img(uploaded_image, target_size=(224, 224))
23
+ img_array = image.img_to_array(img)
24
+ img_array = preprocess_input(img_array)
25
+ img_array = np.expand_dims(img_array, axis=0)
26
+
27
+ # Classify the image using MobileNet
28
+ predictions = model.predict(img_array)
29
+ decoded_predictions = decode_predictions(predictions, top=3)[0]
30
+
31
+ st.subheader("Top Predictions:")
32
+
33
+ for i, (imagenet_id, label, score) in enumerate(decoded_predictions):
34
+ st.write(f"{i + 1}: {label} ({score:.2f})")
35
+