Spaces:
Sleeping
Sleeping
Commit
·
55ca203
1
Parent(s):
cf48067
Im strugglign
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from transformers import pipeline
|
|
| 3 |
from PIL import Image
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
import os
|
| 6 |
-
|
| 7 |
|
| 8 |
# Set page configuration
|
| 9 |
st.set_page_config(
|
|
@@ -17,113 +17,13 @@ def local_css():
|
|
| 17 |
st.markdown(
|
| 18 |
"""
|
| 19 |
<style>
|
| 20 |
-
/*
|
| 21 |
-
.main { background-color: #f5f7fa; }
|
| 22 |
-
|
| 23 |
-
/* Title styling */
|
| 24 |
-
.title h1 {
|
| 25 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 26 |
-
text-align: center;
|
| 27 |
-
color: #007ACC; /* Changed to blue */
|
| 28 |
-
font-size: 3rem;
|
| 29 |
-
margin-bottom: 20px;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
/* Image styling */
|
| 33 |
-
.st-image img {
|
| 34 |
-
border-radius: 15px;
|
| 35 |
-
margin-bottom: 20px;
|
| 36 |
-
max-width: 100%;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
/* Sidebar styling */
|
| 40 |
-
[data-testid="stSidebar"] {
|
| 41 |
-
background-color: #ffffff; /* Changed to white */
|
| 42 |
-
border-right: 1px solid #e6e6e6;
|
| 43 |
-
}
|
| 44 |
-
[data-testid="stSidebar"] .css-ng1t4o { color: #333333; }
|
| 45 |
-
[data-testid="stSidebar"] .css-1d391kg { color: #333333; }
|
| 46 |
-
|
| 47 |
-
/* File uploader styling */
|
| 48 |
-
.stFileUploader {
|
| 49 |
-
border: 2px dashed #007ACC; /* Changed to blue */
|
| 50 |
-
border-radius: 10px;
|
| 51 |
-
padding: 20px;
|
| 52 |
-
text-align: center;
|
| 53 |
-
color: #007ACC; /* Changed to blue */
|
| 54 |
-
background-color: #ffffff;
|
| 55 |
-
font-weight: bold;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
/* File uploader hover effect */
|
| 59 |
-
.stFileUploader:hover {
|
| 60 |
-
background-color: #e6f2ff; /* Light blue hover effect */
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
/* Button styling */
|
| 64 |
-
.stButton>button {
|
| 65 |
-
background-color: #007ACC; /* Changed to blue */
|
| 66 |
-
color: white;
|
| 67 |
-
border: none;
|
| 68 |
-
padding: 0.7rem 1.5rem;
|
| 69 |
-
border-radius: 5px;
|
| 70 |
-
font-size: 1.1rem;
|
| 71 |
-
font-weight: bold;
|
| 72 |
-
margin-top: 10px;
|
| 73 |
-
cursor: pointer;
|
| 74 |
-
}
|
| 75 |
-
.stButton>button:hover {
|
| 76 |
-
background-color: #005a99; /* Darker blue on hover */
|
| 77 |
-
color: white;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/* Headers styling */
|
| 81 |
-
h2 {
|
| 82 |
-
color: #007ACC; /* Changed to blue */
|
| 83 |
-
margin-top: 30px;
|
| 84 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 85 |
-
}
|
| 86 |
-
h3 {
|
| 87 |
-
color: #007ACC; /* Changed to blue */
|
| 88 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
/* Text styling */
|
| 92 |
-
.stMarkdown p { font-size: 1.1rem; color: #333333; }
|
| 93 |
-
|
| 94 |
-
/* Footer styling */
|
| 95 |
-
footer { visibility: hidden; }
|
| 96 |
-
|
| 97 |
-
/* Hide sidebar on small screens */
|
| 98 |
-
@media only screen and (max-width: 600px) {
|
| 99 |
-
[data-testid="stSidebar"] { display: none; }
|
| 100 |
-
.main .block-container { padding-left: 1rem; padding-right: 1rem; }
|
| 101 |
-
.title h1 { font-size: 2rem; }
|
| 102 |
-
.stButton>button { width: 100%; }
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/* Sample images grid */
|
| 106 |
-
.sample-images {
|
| 107 |
-
display: flex;
|
| 108 |
-
justify-content: center;
|
| 109 |
-
flex-wrap: wrap;
|
| 110 |
-
gap: 10px;
|
| 111 |
-
}
|
| 112 |
-
.sample-images img {
|
| 113 |
-
width: 150px;
|
| 114 |
-
height: 150px;
|
| 115 |
-
object-fit: cover;
|
| 116 |
-
border-radius: 10px;
|
| 117 |
-
cursor: pointer;
|
| 118 |
-
border: 2px solid transparent;
|
| 119 |
-
}
|
| 120 |
-
.sample-images img:hover {
|
| 121 |
-
border: 2px solid #007ACC; /* Changed to blue */
|
| 122 |
-
}
|
| 123 |
</style>
|
| 124 |
""", unsafe_allow_html=True
|
| 125 |
)
|
| 126 |
|
|
|
|
|
|
|
| 127 |
# Hugging Face API key
|
| 128 |
API_KEY = st.secrets["HF_API_KEY"]
|
| 129 |
|
|
@@ -157,6 +57,9 @@ def get_ingredients_qwen(food_name):
|
|
| 157 |
except Exception as e:
|
| 158 |
return f"Error generating ingredients: {e}"
|
| 159 |
|
|
|
|
|
|
|
|
|
|
| 160 |
# Main content
|
| 161 |
st.markdown('<div class="title"><h1>DelishAI - Your Culinary Assistant</h1></div>', unsafe_allow_html=True)
|
| 162 |
|
|
@@ -173,14 +76,13 @@ with st.sidebar:
|
|
| 173 |
st.markdown("---")
|
| 174 |
st.markdown("<p style='text-align: center;'>Developed by Muhammad Hassan Butt.</p>", unsafe_allow_html=True)
|
| 175 |
|
| 176 |
-
#
|
| 177 |
-
st.subheader("Or try one of these sample images:")
|
| 178 |
sample_images = {
|
| 179 |
-
"
|
| 180 |
-
"
|
| 181 |
-
|
| 182 |
-
"Salad": "sample_images/salad.jpg"
|
| 183 |
}
|
|
|
|
| 184 |
cols = st.columns(len(sample_images))
|
| 185 |
for idx, (name, file_path) in enumerate(sample_images.items()):
|
| 186 |
with cols[idx]:
|
|
@@ -206,7 +108,7 @@ if 'uploaded_file' in locals() and uploaded_file is not None:
|
|
| 206 |
# Display only the top prediction
|
| 207 |
top_food = predictions[0]['label']
|
| 208 |
st.header(f"🍽️ Food: {top_food}")
|
| 209 |
-
|
| 210 |
# Generate and display ingredients for the top prediction
|
| 211 |
st.subheader("📝 Ingredients")
|
| 212 |
try:
|
|
@@ -215,14 +117,27 @@ if 'uploaded_file' in locals() and uploaded_file is not None:
|
|
| 215 |
except Exception as e:
|
| 216 |
st.error(f"Error generating ingredients: {e}")
|
| 217 |
|
|
|
|
| 218 |
st.subheader("💡 Healthier Alternatives")
|
| 219 |
try:
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
)
|
|
|
|
| 224 |
st.write(result)
|
| 225 |
except Exception as e:
|
| 226 |
-
st.error(f"Unable to
|
| 227 |
else:
|
| 228 |
st.info("Please select or upload an image to get started.")
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
import os
|
| 6 |
+
import openai # Added import
|
| 7 |
|
| 8 |
# Set page configuration
|
| 9 |
st.set_page_config(
|
|
|
|
| 17 |
st.markdown(
|
| 18 |
"""
|
| 19 |
<style>
|
| 20 |
+
/* [Your existing CSS styles here] */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
</style>
|
| 22 |
""", unsafe_allow_html=True
|
| 23 |
)
|
| 24 |
|
| 25 |
+
local_css() # Apply the CSS
|
| 26 |
+
|
| 27 |
# Hugging Face API key
|
| 28 |
API_KEY = st.secrets["HF_API_KEY"]
|
| 29 |
|
|
|
|
| 57 |
except Exception as e:
|
| 58 |
return f"Error generating ingredients: {e}"
|
| 59 |
|
| 60 |
+
# **Set OpenAI API Key**
|
| 61 |
+
openai.api_key = st.secrets["openai"]["api_key"] # Ensure you have this in your secrets
|
| 62 |
+
|
| 63 |
# Main content
|
| 64 |
st.markdown('<div class="title"><h1>DelishAI - Your Culinary Assistant</h1></div>', unsafe_allow_html=True)
|
| 65 |
|
|
|
|
| 76 |
st.markdown("---")
|
| 77 |
st.markdown("<p style='text-align: center;'>Developed by Muhammad Hassan Butt.</p>", unsafe_allow_html=True)
|
| 78 |
|
| 79 |
+
# Assuming `sample_images` is defined somewhere in your code
|
|
|
|
| 80 |
sample_images = {
|
| 81 |
+
"Pizza": "path_to_pizza_image.jpg",
|
| 82 |
+
"Salad": "path_to_salad_image.jpg",
|
| 83 |
+
# Add more sample images as needed
|
|
|
|
| 84 |
}
|
| 85 |
+
|
| 86 |
cols = st.columns(len(sample_images))
|
| 87 |
for idx, (name, file_path) in enumerate(sample_images.items()):
|
| 88 |
with cols[idx]:
|
|
|
|
| 108 |
# Display only the top prediction
|
| 109 |
top_food = predictions[0]['label']
|
| 110 |
st.header(f"🍽️ Food: {top_food}")
|
| 111 |
+
|
| 112 |
# Generate and display ingredients for the top prediction
|
| 113 |
st.subheader("📝 Ingredients")
|
| 114 |
try:
|
|
|
|
| 117 |
except Exception as e:
|
| 118 |
st.error(f"Error generating ingredients: {e}")
|
| 119 |
|
| 120 |
+
# **Healthier Alternatives using OpenAI API**
|
| 121 |
st.subheader("💡 Healthier Alternatives")
|
| 122 |
try:
|
| 123 |
+
response = openai.ChatCompletion.create(
|
| 124 |
+
model="gpt-4o", # You can choose the model you prefer
|
| 125 |
+
messages=[
|
| 126 |
+
{
|
| 127 |
+
"role": "system",
|
| 128 |
+
"content": "You are a helpful assistant specializing in providing healthy alternatives to various dishes."
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"role": "user",
|
| 132 |
+
"content": f"What's a healthy {top_food} recipe, and why is it healthy?"
|
| 133 |
+
}
|
| 134 |
+
],
|
| 135 |
+
max_tokens=200, # Adjust as needed
|
| 136 |
+
temperature=0.7, # Adjust creativity level as needed
|
| 137 |
)
|
| 138 |
+
result = response['choices'][0]['message']['content'].strip()
|
| 139 |
st.write(result)
|
| 140 |
except Exception as e:
|
| 141 |
+
st.error(f"Unable to generate healthier alternatives: {e}")
|
| 142 |
else:
|
| 143 |
st.info("Please select or upload an image to get started.")
|