Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import random
|
| 3 |
-
import streamlit.components.v1 as components
|
| 4 |
|
| 5 |
-
# Sample
|
| 6 |
recipe_data = {
|
| 7 |
"Spaghetti Carbonara": {
|
| 8 |
"ingredients": ["spaghetti", "eggs", "cheese", "pancetta", "garlic", "black pepper"],
|
|
@@ -12,6 +11,18 @@ recipe_data = {
|
|
| 12 |
"ingredients": ["chicken", "lettuce", "tomato", "cucumber", "olive oil", "lemon"],
|
| 13 |
"recipe": "1. Grill the chicken. 2. Prepare the salad with lettuce, tomato, and cucumber. 3. Dress with olive oil and lemon."
|
| 14 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Add more recipes as needed
|
| 16 |
}
|
| 17 |
|
|
@@ -20,17 +31,19 @@ def suggest_dishes(ingredients):
|
|
| 20 |
suggested_dishes = []
|
| 21 |
|
| 22 |
for dish, details in recipe_data.items():
|
|
|
|
| 23 |
if any(ingredient in ingredients for ingredient in details['ingredients']):
|
| 24 |
suggested_dishes.append(dish)
|
| 25 |
|
|
|
|
| 26 |
return random.sample(suggested_dishes, 3) if len(suggested_dishes) >= 3 else suggested_dishes
|
| 27 |
|
| 28 |
-
|
| 29 |
# BMI calculation function
|
| 30 |
def calculate_bmi(weight, height):
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
# Function to categorize BMI
|
| 34 |
def get_bmi_category(bmi):
|
| 35 |
if bmi < 18.5:
|
| 36 |
return "Underweight"
|
|
@@ -41,96 +54,134 @@ def get_bmi_category(bmi):
|
|
| 41 |
else:
|
| 42 |
return "Obese"
|
| 43 |
|
| 44 |
-
|
| 45 |
# Weekly diet plans for different BMI categories
|
| 46 |
diet_plans = {
|
| 47 |
"Underweight": {
|
| 48 |
-
"Breakfast": [
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
},
|
| 52 |
"Normal weight": {
|
| 53 |
-
"Breakfast": [
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
},
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
st.title("Interactive Apps")
|
| 63 |
-
|
| 64 |
-
# Add two buttons to trigger different functionalities
|
| 65 |
-
app_choice = st.radio("Choose an app to run:", ["Floating Cursor with TTS", "BMI Calculator & Diet Plan"])
|
| 66 |
-
|
| 67 |
-
if app_choice == "Floating Cursor with TTS":
|
| 68 |
-
# Floating Cursor with Text-to-Speech app
|
| 69 |
-
st.write("""
|
| 70 |
-
This app creates a floating cursor that can be controlled with the mouse (on laptop) or touch (on mobile).
|
| 71 |
-
Click on any word or sentence, and it will be read aloud in the selected language.
|
| 72 |
-
""")
|
| 73 |
-
|
| 74 |
-
# Language selection dropdown for Text-to-Speech
|
| 75 |
-
language = st.selectbox("Select Language for Text-to-Speech", ("en", "es", "fr", "de", "it", "pt", "ja", "ko", "zh-CN", "ar"))
|
| 76 |
-
|
| 77 |
-
# Embedded HTML and JavaScript for cursor control and text-to-speech
|
| 78 |
-
html_string = f"""
|
| 79 |
-
<html>
|
| 80 |
-
<head>
|
| 81 |
-
<style>
|
| 82 |
-
body {{
|
| 83 |
-
margin: 0;
|
| 84 |
-
}}
|
| 85 |
-
#cursor {{
|
| 86 |
-
position: absolute;
|
| 87 |
-
width: 30px;
|
| 88 |
-
height: 30px;
|
| 89 |
-
background-color: red;
|
| 90 |
-
border-radius: 50%;
|
| 91 |
-
pointer-events: none;
|
| 92 |
-
z-index: 9999;
|
| 93 |
-
}}
|
| 94 |
-
</style>
|
| 95 |
-
</head>
|
| 96 |
-
<body>
|
| 97 |
-
<div id="cursor"></div>
|
| 98 |
-
<div id="floating-text" onclick="speakText(event)" style="padding: 50px; font-size: 18px;">
|
| 99 |
-
<p>Click on any word or sentence below to hear it read aloud.</p>
|
| 100 |
-
<p>This is a <strong>floating cursor</strong> with text-to-speech functionality. <span>Click me</span> to hear me read this sentence aloud.</p>
|
| 101 |
-
<p>Enjoy the interactive cursor experience!</p>
|
| 102 |
-
</div>
|
| 103 |
-
<script>
|
| 104 |
-
const cursor = document.getElementById("cursor");
|
| 105 |
-
const language = "{language}"; // Set the selected language for TTS
|
| 106 |
-
document.addEventListener("mousemove", function(event) {{
|
| 107 |
-
cursor.style.left = event.clientX - cursor.offsetWidth / 2 + "px";
|
| 108 |
-
cursor.style.top = event.clientY - cursor.offsetHeight / 2 + "px";
|
| 109 |
-
}});
|
| 110 |
-
|
| 111 |
-
document.addEventListener("touchmove", function(event) {{
|
| 112 |
-
event.preventDefault();
|
| 113 |
-
const touch = event.touches[0];
|
| 114 |
-
cursor.style.left = touch.clientX - cursor.offsetWidth / 2 + "px";
|
| 115 |
-
cursor.style.top = touch.clientY - cursor.offsetHeight / 2 + "px";
|
| 116 |
-
}});
|
| 117 |
-
|
| 118 |
-
document.body.style.touchAction = "none";
|
| 119 |
-
|
| 120 |
-
function speakText(event) {{
|
| 121 |
-
const selectedText = event.target.innerText;
|
| 122 |
-
const speech = new SpeechSynthesisUtterance(selectedText);
|
| 123 |
-
speech.lang = language;
|
| 124 |
-
window.speechSynthesis.speak(speech);
|
| 125 |
-
}}
|
| 126 |
-
</script>
|
| 127 |
-
</body>
|
| 128 |
-
</html>
|
| 129 |
-
"""
|
| 130 |
-
components.html(html_string, height=500)
|
| 131 |
-
|
| 132 |
-
elif app_choice == "BMI Calculator & Diet Plan":
|
| 133 |
-
# BMI and Diet Plan app
|
| 134 |
st.write("Enter your weight and height to calculate your BMI and get a personalized weekly diet plan.")
|
| 135 |
|
| 136 |
weight = st.number_input("Enter your weight (in kg):", min_value=1.0, max_value=200.0, step=0.1)
|
|
@@ -140,11 +191,12 @@ elif app_choice == "BMI Calculator & Diet Plan":
|
|
| 140 |
if weight > 0 and height > 0:
|
| 141 |
bmi = calculate_bmi(weight, height)
|
| 142 |
st.write(f"Your BMI is: {bmi:.2f}")
|
|
|
|
| 143 |
bmi_category = get_bmi_category(bmi)
|
| 144 |
st.write(f"Your BMI category is: {bmi_category}")
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
if weekly_diet:
|
| 149 |
st.write(f"### Your Weekly Diet Plan:")
|
| 150 |
for meal_time, meals in weekly_diet.items():
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import random
|
|
|
|
| 3 |
|
| 4 |
+
# Sample dataset for dish suggestions and recipes
|
| 5 |
recipe_data = {
|
| 6 |
"Spaghetti Carbonara": {
|
| 7 |
"ingredients": ["spaghetti", "eggs", "cheese", "pancetta", "garlic", "black pepper"],
|
|
|
|
| 11 |
"ingredients": ["chicken", "lettuce", "tomato", "cucumber", "olive oil", "lemon"],
|
| 12 |
"recipe": "1. Grill the chicken. 2. Prepare the salad with lettuce, tomato, and cucumber. 3. Dress with olive oil and lemon."
|
| 13 |
},
|
| 14 |
+
"Beef Stew": {
|
| 15 |
+
"ingredients": ["beef", "carrots", "potatoes", "onion", "garlic", "beef broth"],
|
| 16 |
+
"recipe": "1. Brown the beef. 2. Add carrots, potatoes, and onion. 3. Pour in beef broth and simmer until tender."
|
| 17 |
+
},
|
| 18 |
+
"Vegetable Stir Fry": {
|
| 19 |
+
"ingredients": ["carrot", "broccoli", "bell pepper", "soy sauce", "ginger", "garlic"],
|
| 20 |
+
"recipe": "1. Stir-fry the vegetables in oil. 2. Add soy sauce and ginger. 3. Cook until tender."
|
| 21 |
+
},
|
| 22 |
+
"Pasta Salad": {
|
| 23 |
+
"ingredients": ["pasta", "tomato", "cucumber", "olive oil", "balsamic vinegar"],
|
| 24 |
+
"recipe": "1. Cook pasta. 2. Chop vegetables. 3. Mix all ingredients and season with olive oil and balsamic vinegar."
|
| 25 |
+
},
|
| 26 |
# Add more recipes as needed
|
| 27 |
}
|
| 28 |
|
|
|
|
| 31 |
suggested_dishes = []
|
| 32 |
|
| 33 |
for dish, details in recipe_data.items():
|
| 34 |
+
# Check if the dish contains at least one of the entered ingredients
|
| 35 |
if any(ingredient in ingredients for ingredient in details['ingredients']):
|
| 36 |
suggested_dishes.append(dish)
|
| 37 |
|
| 38 |
+
# Randomly suggest 3 dishes from the possible matches (if there are enough)
|
| 39 |
return random.sample(suggested_dishes, 3) if len(suggested_dishes) >= 3 else suggested_dishes
|
| 40 |
|
|
|
|
| 41 |
# BMI calculation function
|
| 42 |
def calculate_bmi(weight, height):
|
| 43 |
+
bmi = weight / (height ** 2)
|
| 44 |
+
return bmi
|
| 45 |
|
| 46 |
+
# Function to categorize BMI and generate diet plan
|
| 47 |
def get_bmi_category(bmi):
|
| 48 |
if bmi < 18.5:
|
| 49 |
return "Underweight"
|
|
|
|
| 54 |
else:
|
| 55 |
return "Obese"
|
| 56 |
|
|
|
|
| 57 |
# Weekly diet plans for different BMI categories
|
| 58 |
diet_plans = {
|
| 59 |
"Underweight": {
|
| 60 |
+
"Breakfast": [
|
| 61 |
+
{"dish": "Avocado Toast", "calories": 400},
|
| 62 |
+
{"dish": "Peanut Butter Smoothie", "calories": 350},
|
| 63 |
+
{"dish": "Oatmeal with Almonds", "calories": 300}
|
| 64 |
+
],
|
| 65 |
+
"Lunch": [
|
| 66 |
+
{"dish": "Grilled Chicken Salad", "calories": 500},
|
| 67 |
+
{"dish": "Pasta with Pesto", "calories": 600},
|
| 68 |
+
{"dish": "Quinoa and Black Beans", "calories": 450}
|
| 69 |
+
],
|
| 70 |
+
"Dinner": [
|
| 71 |
+
{"dish": "Salmon with Sweet Potatoes", "calories": 600},
|
| 72 |
+
{"dish": "Chicken Stir Fry with Veggies", "calories": 550},
|
| 73 |
+
{"dish": "Beef Tacos", "calories": 650}
|
| 74 |
+
]
|
| 75 |
},
|
| 76 |
"Normal weight": {
|
| 77 |
+
"Breakfast": [
|
| 78 |
+
{"dish": "Scrambled Eggs with Spinach", "calories": 350},
|
| 79 |
+
{"dish": "Greek Yogurt with Berries", "calories": 250},
|
| 80 |
+
{"dish": "Whole Wheat Toast with Avocado", "calories": 300}
|
| 81 |
+
],
|
| 82 |
+
"Lunch": [
|
| 83 |
+
{"dish": "Chicken Caesar Salad", "calories": 500},
|
| 84 |
+
{"dish": "Veggie Wrap", "calories": 400},
|
| 85 |
+
{"dish": "Grilled Fish Tacos", "calories": 550}
|
| 86 |
+
],
|
| 87 |
+
"Dinner": [
|
| 88 |
+
{"dish": "Grilled Chicken with Rice", "calories": 600},
|
| 89 |
+
{"dish": "Vegetable Stir Fry", "calories": 450},
|
| 90 |
+
{"dish": "Spaghetti with Marinara", "calories": 550}
|
| 91 |
+
]
|
| 92 |
+
},
|
| 93 |
+
"Overweight": {
|
| 94 |
+
"Breakfast": [
|
| 95 |
+
{"dish": "Greek Yogurt with Granola", "calories": 250},
|
| 96 |
+
{"dish": "Scrambled Egg Whites with Veggies", "calories": 200},
|
| 97 |
+
{"dish": "Smoothie with Kale and Berries", "calories": 220}
|
| 98 |
+
],
|
| 99 |
+
"Lunch": [
|
| 100 |
+
{"dish": "Chicken Salad with Low-Cal Dressing", "calories": 400},
|
| 101 |
+
{"dish": "Grilled Chicken and Vegetables", "calories": 350},
|
| 102 |
+
{"dish": "Tofu Stir Fry", "calories": 300}
|
| 103 |
+
],
|
| 104 |
+
"Dinner": [
|
| 105 |
+
{"dish": "Baked Salmon with Veggies", "calories": 450},
|
| 106 |
+
{"dish": "Turkey Meatballs with Zucchini Noodles", "calories": 500},
|
| 107 |
+
{"dish": "Grilled Shrimp with Quinoa", "calories": 400}
|
| 108 |
+
]
|
| 109 |
},
|
| 110 |
+
"Obese": {
|
| 111 |
+
"Breakfast": [
|
| 112 |
+
{"dish": "Omelette with Veggies", "calories": 250},
|
| 113 |
+
{"dish": "Cottage Cheese with Berries", "calories": 200},
|
| 114 |
+
{"dish": "Chia Seed Pudding", "calories": 150}
|
| 115 |
+
],
|
| 116 |
+
"Lunch": [
|
| 117 |
+
{"dish": "Chicken and Veggie Soup", "calories": 350},
|
| 118 |
+
{"dish": "Salmon Salad with Olive Oil", "calories": 400},
|
| 119 |
+
{"dish": "Grilled Tofu with Broccoli", "calories": 350}
|
| 120 |
+
],
|
| 121 |
+
"Dinner": [
|
| 122 |
+
{"dish": "Baked Chicken Breast with Asparagus", "calories": 450},
|
| 123 |
+
{"dish": "Steamed Fish with Veggies", "calories": 400},
|
| 124 |
+
{"dish": "Roasted Cauliflower with Lentils", "calories": 350}
|
| 125 |
+
]
|
| 126 |
+
}
|
| 127 |
}
|
| 128 |
|
| 129 |
+
# Function to generate weekly diet plan
|
| 130 |
+
def generate_weekly_diet(bmi_category):
|
| 131 |
+
diet = diet_plans.get(bmi_category)
|
| 132 |
+
if not diet:
|
| 133 |
+
return None
|
| 134 |
+
|
| 135 |
+
weekly_diet = {"Breakfast": [], "Lunch": [], "Dinner": []}
|
| 136 |
+
for meal_time, meals in diet.items():
|
| 137 |
+
# If there are fewer than 7 meals, repeat them to fill the week
|
| 138 |
+
num_meals = len(meals)
|
| 139 |
+
if num_meals < 7:
|
| 140 |
+
# Repeat meals to ensure there are 7 meals (one for each day of the week)
|
| 141 |
+
weekly_diet[meal_time] = (meals * (7 // num_meals)) + meals[:(7 % num_meals)]
|
| 142 |
+
else:
|
| 143 |
+
# Randomly sample 7 meals if there are enough
|
| 144 |
+
weekly_diet[meal_time] = random.sample(meals, 7)
|
| 145 |
+
|
| 146 |
+
return weekly_diet
|
| 147 |
+
|
| 148 |
+
# Streamlit App Interface
|
| 149 |
+
st.title("Select an App to Use")
|
| 150 |
+
st.write("Choose one of the following options:")
|
| 151 |
+
|
| 152 |
+
# Buttons to trigger respective apps
|
| 153 |
+
app_choice = st.radio(
|
| 154 |
+
"Choose App",
|
| 155 |
+
("Cooking Suggestion App", "BMI Calculator and Diet Plan")
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
if app_choice == "Cooking Suggestion App":
|
| 159 |
+
st.write("Enter 1 or 2 ingredients to get recipe suggestions:")
|
| 160 |
+
|
| 161 |
+
ingredients_input = st.text_input("Enter ingredients (comma separated):")
|
| 162 |
+
|
| 163 |
+
if st.button("Suggest Dishes"):
|
| 164 |
+
if ingredients_input:
|
| 165 |
+
ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')]
|
| 166 |
+
st.write("Entered Ingredients:", ingredients)
|
| 167 |
+
|
| 168 |
+
if ingredients:
|
| 169 |
+
suggested_dishes = suggest_dishes(ingredients)
|
| 170 |
+
if suggested_dishes:
|
| 171 |
+
st.write("Suggested Dishes:")
|
| 172 |
+
selected_dish = st.selectbox("Choose a dish", suggested_dishes)
|
| 173 |
+
|
| 174 |
+
if selected_dish:
|
| 175 |
+
st.write(f"Recipe for {selected_dish}:")
|
| 176 |
+
st.write(recipe_data[selected_dish]["recipe"])
|
| 177 |
+
else:
|
| 178 |
+
st.write("No dishes found for the entered ingredients.")
|
| 179 |
+
else:
|
| 180 |
+
st.write("No valid ingredients entered.")
|
| 181 |
+
else:
|
| 182 |
+
st.write("Please enter some ingredients.")
|
| 183 |
|
| 184 |
+
elif app_choice == "BMI Calculator and Diet Plan":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
st.write("Enter your weight and height to calculate your BMI and get a personalized weekly diet plan.")
|
| 186 |
|
| 187 |
weight = st.number_input("Enter your weight (in kg):", min_value=1.0, max_value=200.0, step=0.1)
|
|
|
|
| 191 |
if weight > 0 and height > 0:
|
| 192 |
bmi = calculate_bmi(weight, height)
|
| 193 |
st.write(f"Your BMI is: {bmi:.2f}")
|
| 194 |
+
|
| 195 |
bmi_category = get_bmi_category(bmi)
|
| 196 |
st.write(f"Your BMI category is: {bmi_category}")
|
| 197 |
|
| 198 |
+
weekly_diet = generate_weekly_diet(bmi_category)
|
| 199 |
+
|
| 200 |
if weekly_diet:
|
| 201 |
st.write(f"### Your Weekly Diet Plan:")
|
| 202 |
for meal_time, meals in weekly_diet.items():
|