Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910114 unmodified lines1617181920212223242526272829303132333435363711 unmodified lines49505152535455import streamlit as stfrom transformers import pipeline, AutoTokenizer, AutoModelForCausalLMfrom PIL import Imageimport os# Hugging Face token login (add this as a secret in Hugging Face Spaces)os.environ["HF_TOKEN"] = st.secrets["HF_AUTH_TOKEN"]# Load the image classification pipeline@st.cache_resourcedef load_image_classification_pipeline():4 unmodified linespipe_classification = load_image_classification_pipeline()# Load the Llama model for ingredient generation@st.cache_resourcedef load_llama_pipeline():"""Load the Llama model for ingredient generation."""tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct", use_auth_token=os.environ["HF_TOKEN"])model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct", use_auth_token=os.environ["HF_TOKEN"])return pipeline("text-generation", model=model, tokenizer=tokenizer)pipe_llama = load_llama_pipeline()# Function to generate ingredients using the Llama modeldef get_ingredients_llama(food_name):"""Generate a list of ingredients for the given food item using the Llama model."""prompt = f"List the main ingredients typically used to prepare {food_name}."try:11 unmodified lines# Sidebar for model informationst.sidebar.title("Model Information")st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")st.sidebar.write("**LLM for Ingredients**: meta-llama/Llama-3.2-3B-Instruct")# Upload imageuploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])123456784 unmodified lines131415161718192021222324252627282930313211 unmodified lines44454647484950import streamlit as stfrom transformers import pipelinefrom PIL import Imageimport os# Load the image classification pipeline@st.cache_resourcedef load_image_classification_pipeline():4 unmodified linespipe_classification = load_image_classification_pipeline()# Load the GPT-Neo model for ingredient generation@st.cache_resourcedef load_llama_pipeline():"""Load the GPT-Neo model for ingredient generation."""return pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")pipe_llama = load_llama_pipeline()# Function to generate ingredients using GPT-Neodef get_ingredients_llama(food_name):"""Generate a list of ingredients for the given food item using GPT-Neo."""prompt = f"List the main ingredients typically used to prepare {food_name}."try:11 unmodified lines# Sidebar for model informationst.sidebar.title("Model Information")st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")st.sidebar.write("**LLM for Ingredients**: EleutherAI/gpt-neo-1.3B")# Upload imageuploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])
app.py+7-12