Spaces:
Sleeping
Sleeping
Update app.py
Browse files37 unmodified lines3839404137 unmodified linesresponse = pipe_bloom(prompt, max_length=50, num_return_sequences=1)generated_text = response[0]["generated_text"].strip()# Post-process the response37 unmodified lines3839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888937 unmodified linesresponse = pipe_bloom(prompt, max_length=50, num_return_sequences=1)generated_text = response[0]["generated_text"].strip()# Post-process the responseingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."ingredients = ingredients.replace(".", "").strip() # Remove periods and extra spaces# Validate the response to ensure no placeholdersif "ingredient1" in ingredients.lower() or "example" in ingredients.lower():return "No valid ingredients found. Try again with a different food."return ingredientsexcept Exception as e:return f"Error generating ingredients: {e}"# Streamlit app setupst.title("Food Image Recognition with Ingredients")# Add banner imagest.image("IR_IMAGE.png", caption="Food Recognition Model", use_column_width=True)# Sidebar for model informationst.sidebar.title("Model Information")st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")st.sidebar.write("**LLM for Ingredients**: bigscience/bloom-1b7")# Upload imageuploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])if uploaded_file is not None:# Display the uploaded imageimage = Image.open(uploaded_file)st.image(image, caption="Uploaded Image", use_column_width=True)st.write("Classifying...")# Make predictionspredictions = pipe_classification(image)# Display only the top predictiontop_food = predictions[0]['label']st.header(f"Food: {top_food}")# Generate and display ingredients for the top predictionst.subheader("Ingredients")try:ingredients = get_ingredients_bloom(top_food)st.write(ingredients)except Exception as e:st.error(f"Error generating ingredients: {e}")# Footerst.sidebar.markdown("Created with ❤️ using Streamlit and Hugging Face.")
app.py+49-1