Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,21 @@ import base64
|
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import os
|
5 |
|
6 |
-
# Initialize Hugging Face Inference
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
# 1. Function to identify dish from image
|
11 |
def identify_dish(image_bytes):
|
12 |
encoded_image = base64.b64encode(image_bytes).decode("utf-8")
|
13 |
dish_name = ""
|
14 |
|
15 |
-
for message in
|
16 |
-
model="meta-llama/Llama-3-11B-Vision-Instruct",
|
17 |
messages=[
|
18 |
{
|
19 |
"role": "You are a highly specialized food identification AI with extensive knowledge of global cuisines. Your sole task is to accurately identify dishes from images. Adhere strictly to these guidelines:\n1. Analyze the image thoroughly, focusing on ingredients, presentation, and cultural context.\n2. Provide ONLY the name of the main dish or dishes visible. Do not list individual ingredients or components.\n3. Use the most specific and widely recognized name for the dish.\n4. If multiple distinct dishes are present, list them separated by commas.\n5. If you cannot identify a dish with high confidence (>90%), respond with 'Unidentified dish'.\n6. Do not provide any explanations, descriptions, or additional commentary.\n7. Respond in a concise, list-like format.\nYour response should contain nothing but the dish name(s) or 'Unidentified dish'.",
|
20 |
"content": [
|
21 |
-
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{encoded_image}"}},
|
22 |
{"type": "text", "text": "Identify the dishes in the image and return only the names of the dishes."},
|
23 |
],
|
24 |
}
|
@@ -85,8 +84,9 @@ def generate_diet_plan(dish_name, calorie_intake_per_day, goal):
|
|
85 |
- Dish Name: {dish_name}
|
86 |
- Caloric Intake per Day: {calorie_intake_per_day} calories
|
87 |
- Goal: {goal}
|
|
|
88 |
"""
|
89 |
-
response =
|
90 |
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
91 |
messages=[{"role": "You are a certified Dietitian with 20 years of Experience", "content": user_input}],
|
92 |
max_tokens=500
|
@@ -100,10 +100,10 @@ st.title("AI Diet Planner")
|
|
100 |
# Sidebar for user input
|
101 |
st.sidebar.title("User Input")
|
102 |
image_file = st.sidebar.file_uploader("Upload an image of the dish", type=["jpeg", "png"])
|
103 |
-
age = st.sidebar.number_input("Enter your age", min_value=
|
104 |
gender = st.sidebar.selectbox("Select your gender", ["male", "female"])
|
105 |
-
height_cm = st.sidebar.number_input("Enter your height (cm)", min_value=
|
106 |
-
weight_kg = st.sidebar.number_input("Enter your weight (kg)", min_value=
|
107 |
weight_goal = st.sidebar.selectbox("Weight goal", ["loss", "gain", "maintain"])
|
108 |
activity_level = st.sidebar.selectbox("Activity level", ["sedentary", "light", "moderate", "active", "very active"])
|
109 |
time_frame = st.sidebar.number_input("Time frame to achieve goal (months)", min_value=1)
|
|
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import os
|
5 |
|
6 |
+
# Initialize Hugging Face Inference client using token from environment variables
|
7 |
+
client = InferenceClient(api_key=os.getenv("HF_API_TOKEN_DISH"))
|
8 |
+
client1 = InferenceClient(api_key=os.getenv("HF_API_TOKEN_DIET"))
|
|
|
9 |
# 1. Function to identify dish from image
|
10 |
def identify_dish(image_bytes):
|
11 |
encoded_image = base64.b64encode(image_bytes).decode("utf-8")
|
12 |
dish_name = ""
|
13 |
|
14 |
+
for message in client.chat_completion(
|
15 |
+
model="meta-llama/Llama-3.2-11B-Vision-Instruct",
|
16 |
messages=[
|
17 |
{
|
18 |
"role": "You are a highly specialized food identification AI with extensive knowledge of global cuisines. Your sole task is to accurately identify dishes from images. Adhere strictly to these guidelines:\n1. Analyze the image thoroughly, focusing on ingredients, presentation, and cultural context.\n2. Provide ONLY the name of the main dish or dishes visible. Do not list individual ingredients or components.\n3. Use the most specific and widely recognized name for the dish.\n4. If multiple distinct dishes are present, list them separated by commas.\n5. If you cannot identify a dish with high confidence (>90%), respond with 'Unidentified dish'.\n6. Do not provide any explanations, descriptions, or additional commentary.\n7. Respond in a concise, list-like format.\nYour response should contain nothing but the dish name(s) or 'Unidentified dish'.",
|
19 |
"content": [
|
20 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{encoded_image}" }},
|
21 |
{"type": "text", "text": "Identify the dishes in the image and return only the names of the dishes."},
|
22 |
],
|
23 |
}
|
|
|
84 |
- Dish Name: {dish_name}
|
85 |
- Caloric Intake per Day: {calorie_intake_per_day} calories
|
86 |
- Goal: {goal}
|
87 |
+
|
88 |
"""
|
89 |
+
response = client1.chat_completion(
|
90 |
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
91 |
messages=[{"role": "You are a certified Dietitian with 20 years of Experience", "content": user_input}],
|
92 |
max_tokens=500
|
|
|
100 |
# Sidebar for user input
|
101 |
st.sidebar.title("User Input")
|
102 |
image_file = st.sidebar.file_uploader("Upload an image of the dish", type=["jpeg", "png"])
|
103 |
+
age = st.sidebar.number_input("Enter your age", min_value=1)
|
104 |
gender = st.sidebar.selectbox("Select your gender", ["male", "female"])
|
105 |
+
height_cm = st.sidebar.number_input("Enter your height (cm)", min_value=1.0)
|
106 |
+
weight_kg = st.sidebar.number_input("Enter your weight (kg)", min_value=1.0)
|
107 |
weight_goal = st.sidebar.selectbox("Weight goal", ["loss", "gain", "maintain"])
|
108 |
activity_level = st.sidebar.selectbox("Activity level", ["sedentary", "light", "moderate", "active", "very active"])
|
109 |
time_frame = st.sidebar.number_input("Time frame to achieve goal (months)", min_value=1)
|