Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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(
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
temp_file_path = temp_file.name
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
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
|
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",
|