Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line234557678910111213142 unmodified lines171819182021222123242526272829282930313233303135363738394032333435363714 unmodified lines52535461555657581 unmodified linefrom transformers import pipelinefrom PIL import Imageimport openaiimport os
# Set your OpenAI API key (replace YOUR_OPENAI_API_KEY with your key)# Set your OpenAI API keyopenai.api_key = "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"
# OpenAI model to useOPENAI_MODEL = "gpt-4o" # Replace with the model you want to display
# Load the image classification pipeline@st.cache_resourcedef load_image_classification_pipeline():2 unmodified linespipe_classification = load_image_classification_pipeline()
# Function to generate ingredients using OpenAIdef get_ingredients_openai(food_name, model="text-davinci-003"):def get_ingredients_openai(food_name): prompt = f"List the main ingredients typically used to prepare {food_name}:" response = openai.Completion.create( engine=model, # Specify the model here engine=OPENAI_MODEL, prompt=prompt, max_tokens=50 ) return response['choices'][0]['text'].strip()
# Streamlit appst.title("Food Image Recognition Model")st.write("Upload an image to classify the type of food and get its ingredients!")
# Display a sample image showing the concept of image recognitionst.image("/Users/hassanbutt/Desktop/Screenshot 2024-11-19 at 8.04.00 PM.png", caption="Example of an Image Recognition Model", use_column_width=True)st.title("Food Image Recognition with Ingredients")
# Select OpenAI modelst.sidebar.title("Choose a Model")model_choice = st.sidebar.selectbox( "Select an OpenAI Model:", ["text-davinci-003", "gpt-3.5-turbo", "gpt-4", "curie"])# Display OpenAI model being usedst.sidebar.title("Model Information")st.sidebar.write(f"**OpenAI Model Used**: {OPENAI_MODEL}")
# Upload imageuploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])14 unmodified lines # Generate and display ingredients for the top prediction st.subheader("Ingredients") try: ingredients = get_ingredients_openai(top_food, model=model_choice) ingredients = get_ingredients_openai(top_food) st.write(ingredients) except Exception as e: st.write("Could not generate ingredients. Please try again later.")app.py+11-17