File size: 1,525 Bytes
77368f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import streamlit as st
import pandas as pd
import numpy as np
import cv2
from PIL import Image
import tensorflow as tf
# Function to load the model
@st.cache_resource
def load_model():
model = tf.keras.models.load_model('path_to_your_saved_model.h5') # Provide the path to your model
return model
# Function to preprocess the image
def preprocess_image(image):
image = np.array(image.convert('RGB'))
image = cv2.resize(image, (224, 224)) # Resize the image to the input shape required by your model
image = image / 255.0 # Normalize the image
image = np.expand_dims(image, axis=0)
return image
# Function to predict the class
def predict(image, model):
processed_image = preprocess_image(image)
prediction = model.predict(processed_image)
return prediction
# Main app
def main():
st.title("Food Item Recognition and Estimation")
st.write("Upload an image of a food item and the model will recognize the food item and estimate its calories.")
model = load_model()
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
st.write("")
st.write("Classifying...")
prediction = predict(image, model)
st.write(f"Predicted class: {np.argmax(prediction)}") # Update with your model's prediction logic
if __name__ == "__main__":
main()
|