|
|
import streamlit as st |
|
|
import cv2 |
|
|
import os |
|
|
from app import * |
|
|
import pprint |
|
|
|
|
|
|
|
|
if not os.path.exists("captured_images"): |
|
|
os.makedirs("captured_images") |
|
|
|
|
|
background_style = """ |
|
|
<style> |
|
|
[data-testid="stAppViewContainer"] { |
|
|
background-image: url('https://i.ibb.co/HpYr6qg/Untitled-design-2.png'); |
|
|
background-size: cover; |
|
|
background-repeat: no-repeat; |
|
|
background-attachment: fixed; |
|
|
} |
|
|
</style> |
|
|
""" |
|
|
st.markdown(background_style, unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
session_state = st.session_state |
|
|
if 'ingredientsList' not in session_state: |
|
|
session_state['ingredientsList'] = ["apple", "orange", "orange"] |
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
|
col1, col2 = st.columns([1, 5]) |
|
|
|
|
|
|
|
|
with col1: |
|
|
logo = st.image("https://d112y698adiu2z.cloudfront.net/photos/production/software_thumbnail_photos/002/589/585/datas/medium.png", width=150) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with col2: |
|
|
st.title('RecipeBud') |
|
|
|
|
|
st.sidebar.header('Ingredients & Nutrition') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cap = cv2.VideoCapture(0) |
|
|
|
|
|
|
|
|
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 800) |
|
|
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 400) |
|
|
|
|
|
|
|
|
if not cap.isOpened(): |
|
|
st.error("Error: Unable to access the webcam.") |
|
|
return |
|
|
|
|
|
|
|
|
video_placeholder = st.empty() |
|
|
|
|
|
|
|
|
st.markdown( |
|
|
""" |
|
|
<style> |
|
|
.stButton>button { |
|
|
background-color: #4CAF50; /* Green */ |
|
|
color: white; |
|
|
border: none; |
|
|
border-radius: 5px; |
|
|
} |
|
|
</style> |
|
|
""", |
|
|
unsafe_allow_html=True |
|
|
) |
|
|
|
|
|
|
|
|
if st.button("Capture Image"): |
|
|
image_path = capture_image() |
|
|
classification = classifyImage(image_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button_clicked = st.sidebar.button('Done') |
|
|
|
|
|
|
|
|
while not button_clicked: |
|
|
|
|
|
ret, frame = cap.read() |
|
|
|
|
|
if not ret: |
|
|
st.error("Error: Unable to read frame from the webcam.") |
|
|
break |
|
|
|
|
|
|
|
|
video_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), channels="RGB", use_column_width=True) |
|
|
if button_clicked: |
|
|
nutrition_values = analyze_nutrition(nutrients(session_state['ingredientsList'])) |
|
|
cap.release() |
|
|
if session_state['ingredientsList']: |
|
|
session_state['ingredientsList'].pop() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content = {} |
|
|
for ingredient in nutrition_values: |
|
|
|
|
|
content[ingredient] = nutrition_values[ingredient] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ingredient in content: |
|
|
with st.sidebar.expander(ingredient): |
|
|
ingred = str(content[ingredient]) |
|
|
st.write(ingred[1:len(ingred)-1].replace("'", "").replace(',', '\n\n')) |
|
|
displayRecipes(session_state['ingredientsList']) |
|
|
|
|
|
|
|
|
|
|
|
def displayRecipes(ingredientsList): |
|
|
items = [] |
|
|
|
|
|
prompt = f"I have following Ingredients :{','.join(ingredientsList)}. What can I make with these \ |
|
|
Ingredients? Give me A list of detailed recipes with measurements containing these ingredients with Nutrition Facts (calories, grams of sugar, grams of protein, grams of fats, grams of carbohydrates) per serving based on the widely accepted nutritional value of each of these ingredients. Rank the list from \ |
|
|
highest nutritional value to lowest. Give me results in \ |
|
|
following format and do not deviate from this format:\ |
|
|
['Recipe Title', 'Calories per serving']." |
|
|
|
|
|
LLMResult = askGPT(prompt) |
|
|
lystOfRecipes = LLMResult.split('\n\n') |
|
|
|
|
|
count = 0 |
|
|
for recipe in range(1,len(lystOfRecipes)-1): |
|
|
count += 1 |
|
|
items.append({"title": lystOfRecipes[recipe].split(":")[0], "content": ""}) |
|
|
if count == 4: |
|
|
break |
|
|
|
|
|
for item in items: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with st.expander(item["title"]): |
|
|
st.write(askGPT(f"Give me a detailed recipe for a dish called {item['title']} containing all of the following ingredients: {','.join(ingredientsList)}. Make sure your response is easy to follow and comprehensive.")) |
|
|
|
|
|
|
|
|
def capture_image(): |
|
|
|
|
|
cap = cv2.VideoCapture(0) |
|
|
|
|
|
|
|
|
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 800) |
|
|
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 400) |
|
|
|
|
|
|
|
|
if not cap.isOpened(): |
|
|
st.error("Error: Unable to access the webcam.") |
|
|
return |
|
|
|
|
|
|
|
|
ret, frame = cap.read() |
|
|
|
|
|
if not ret: |
|
|
st.error("Error: Unable to read frame from the webcam.") |
|
|
return |
|
|
|
|
|
|
|
|
image_path = f"captured_images/captured_image_{len(os.listdir('captured_images')) + 1}.jpg" |
|
|
cv2.imwrite(image_path, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)) |
|
|
st.success(f"Image captured and saved as {image_path}") |
|
|
|
|
|
|
|
|
cap.release() |
|
|
|
|
|
return image_path |
|
|
|
|
|
|
|
|
def nutrients(ingredients): |
|
|
formatted_list = [] |
|
|
for ingredient in ingredients: |
|
|
formatted_list.append(ingredient + " per 100 grams") |
|
|
return formatted_list |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
main() |
|
|
|