stchakman commited on
Commit
92f3574
·
1 Parent(s): 08dd082

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -26,19 +26,22 @@ ingredient_names = list(term_variables)
26
 
27
  classifier = pipeline("image-classification", model="stchakman/Fridge_Items_Model")
28
 
29
- def extract_ingredients(image):
30
- # Save the PIL Image as a temporary file
31
- with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
32
- image.save(temp_file, format="JPEG")
33
- temp_file_path = temp_file.name
34
 
35
- preds = classifier(temp_file_path)
36
- predictions = [pred["label"] for pred in preds]
37
- return [prediction for prediction in predictions if prediction in ingredient_names]
 
 
 
 
38
 
39
  def generate_dishes(ingredients, n=3, max_tokens=150, temperature=0.7):
40
  ingredients_str = ', '.join(ingredients)
41
- prompt = f"I have {ingredients_str} Please return the name of a dish I can make followed by intructions on how to prepare that dish "
42
 
43
  response = openai.Completion.create(
44
  model="text-davinci-003",
 
26
 
27
  classifier = pipeline("image-classification", model="stchakman/Fridge_Items_Model")
28
 
29
+ def extract_ingredients(uploaded_image):
30
+ temp_file = tempfile.NamedTemporaryFile(delete=False)
31
+ temp_file.write(uploaded_image.getvalue())
32
+ temp_file.flush()
 
33
 
34
+ image = Image.open(temp_file.name)
35
+ preds = classifier(temp_file.name)
36
+ ingredients = [label for score, label in preds]
37
+
38
+ temp_file.close()
39
+ os.unlink(temp_file.name)
40
+ return ingredients
41
 
42
  def generate_dishes(ingredients, n=3, max_tokens=150, temperature=0.7):
43
  ingredients_str = ', '.join(ingredients)
44
+ prompt = f"I have {ingredients_str} Please return the name of a dish I can make followed by instructions on how to prepare that dish"
45
 
46
  response = openai.Completion.create(
47
  model="text-davinci-003",