stchakman commited on
Commit
08dd082
·
1 Parent(s): 15c7520

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -33
app.py CHANGED
@@ -51,14 +51,14 @@ def generate_dishes(ingredients, n=3, max_tokens=150, temperature=0.7):
51
  dishes = [choice.text.strip() for choice in response.choices]
52
  return dishes
53
 
54
- def generate_image(prompt):
55
- model_id = "runwayml/stable-diffusion-v1-5"
56
- pipe = StableDiffusionPipeline.from_pretrained(model_id)
57
 
 
 
 
58
  # If you have a GPU available, uncomment the following line
59
- pipe = pipe.to("cuda")
60
-
61
- image = pipe(prompt).images[0]
62
  return image
63
 
64
  def get_image_download_link(image, filename, text):
@@ -70,35 +70,20 @@ def get_image_download_link(image, filename, text):
70
 
71
  st.title("Fridge to Dish App")
72
 
73
- uploaded_image = st.file_uploader("Upload an image of your fridge", type=["jpg", "jpeg", "png"])
74
 
75
  if uploaded_image is not None:
76
- image = Image.open(uploaded_image)
77
- st.image(image, caption="Uploaded Fridge Image, Please wait", use_column_width=True)
78
-
79
- ingredients = extract_ingredients(image)
80
- st.write("Detected Ingredients:")
81
- st.write(ingredients)
82
 
83
  suggested_dishes = generate_dishes(ingredients)
 
 
 
 
 
 
84
 
85
- if suggested_dishes:
86
- st.write("Suggested Dishes:")
87
- for dish in suggested_dishes:
88
- st.write(dish)
89
-
90
- if st.button("Generate Image for Dish 1"):
91
- dish1_image = generate_image(suggested_dishes[0].split(":")[0])
92
- st.image(dish1_image, caption=f"Generated Image for {suggested_dishes[0].split(':')[0]}", use_column_width=True)
93
-
94
- if st.button("Generate Image for Dish 2"):
95
- dish2_image = generate_image(suggested_dishes[1].split(":")[0])
96
- st.image(dish2_image, caption=f"Generated Image for {suggested_dishes[1].split(':')[0]}", use_column_width=True)
97
-
98
- if st.button("Generate Image for Dish 3"):
99
- dish3_image = generate_image(suggested_dishes[2].split(":")[0])
100
- st.image(dish3_image, caption=f"Generated Image for {suggested_dishes[2].split(':')[0]}", use_column_width=True)
101
- else:
102
- st.write("No dishes found")
103
- else:
104
- st.write("Please upload an image")
 
51
  dishes = [choice.text.strip() for choice in response.choices]
52
  return dishes
53
 
54
+ model_id = "runwayml/stable-diffusion-v1-5"
 
 
55
 
56
+ def generate_image(prompt):
57
+ with st.spinner("Generating image..."):
58
+ pipe = StableDiffusionPipeline.from_pretrained(model_id)
59
  # If you have a GPU available, uncomment the following line
60
+ pipe = pipe.to("cuda")
61
+ image = pipe(prompt).images[0]
 
62
  return image
63
 
64
  def get_image_download_link(image, filename, text):
 
70
 
71
  st.title("Fridge to Dish App")
72
 
73
+ uploaded_image = st.file_uploader("Upload an image of your fridge", type=["jpg", "jpeg"])
74
 
75
  if uploaded_image is not None:
76
+ ingredients = extract_ingredients(uploaded_image)
77
+ st.write(f"Identified ingredients: {', '.join(ingredients)}")
 
 
 
 
78
 
79
  suggested_dishes = generate_dishes(ingredients)
80
+ st.write("Suggested dishes:")
81
+
82
+ for idx, dish in enumerate(suggested_dishes):
83
+ st.write(f"{idx + 1}. {dish}")
84
+
85
+ selected_dish = st.radio("Select a dish to generate an image", suggested_dishes)
86
 
87
+ if selected_dish:
88
+ generated_image = generate_image(selected_dish)
89
+ st.image(generated_image, caption=selected_dish, use_column_width=True)