Food-app / app.py
shallou's picture
Create app.py
77368f6 verified
raw
history blame
1.53 kB
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()