HassanDataSci commited on
Commit
d469986
·
verified ·
1 Parent(s): a34ab64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -41
app.py CHANGED
@@ -23,6 +23,7 @@ def load_bloom_pipeline():
23
 
24
  pipe_bloom = load_bloom_pipeline()
25
 
 
26
  def get_ingredients_bloom(food_name):
27
  """
28
  Generate a list of ingredients for the given food item using BLOOM.
@@ -37,44 +38,4 @@ def get_ingredients_bloom(food_name):
37
  response = pipe_bloom(prompt, max_length=50, num_return_sequences=1)
38
  generated_text = response[0]["generated_text"].strip()
39
 
40
- # Post-process the response
41
- ingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."
42
- ingredients = ingredients.replace(".", "").strip() # Remove periods and return f"Error generating ingredients: {e}"
43
-
44
- # Streamlit app setup
45
- st.title("Food Image Recognition with Ingredients")
46
-
47
- # Add banner image
48
- st.image("IR_IMAGE.png", caption="Food Recognition Model", use_column_width=True)
49
-
50
- # Sidebar for model information
51
- st.sidebar.title("Model Information")
52
- st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")
53
- st.sidebar.write("**LLM for Ingredients**: bigscience/bloom-1b7")
54
-
55
- # Upload image
56
- uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])
57
-
58
- if uploaded_file is not None:
59
- # Display the uploaded image
60
- image = Image.open(uploaded_file)
61
- st.image(image, caption="Uploaded Image", use_column_width=True)
62
- st.write("Classifying...")
63
-
64
- # Make predictions
65
- predictions = pipe_classification(image)
66
-
67
- # Display only the top prediction
68
- top_food = predictions[0]['label']
69
- st.header(f"Food: {top_food}")
70
-
71
- # Generate and display ingredients for the top prediction
72
- st.subheader("Ingredients")
73
- try:
74
- ingredients = get_ingredients_bloom(top_food)
75
- st.write(ingredients)
76
- except Exception as e:
77
- st.error(f"Error generating ingredients: {e}")
78
-
79
- # Footer
80
- st.sidebar.markdown("Created with ❤️ using Streamlit and Hugging Face.")
 
23
 
24
  pipe_bloom = load_bloom_pipeline()
25
 
26
+ # Function to generate ingredients using BLOOM
27
  def get_ingredients_bloom(food_name):
28
  """
29
  Generate a list of ingredients for the given food item using BLOOM.
 
38
  response = pipe_bloom(prompt, max_length=50, num_return_sequences=1)
39
  generated_text = response[0]["generated_text"].strip()
40
 
41
+ # Post-process the response