Spaces:
Sleeping
Sleeping
Commit ·
55ca203
1
Parent(s): cf48067
Im strugglign
Browse files2 unmodified lines34567897 unmodified lines171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812927 unmodified lines15715815916016116210 unmodified lines17317417517617717817918018118218318418518619 unmodified lines2062072082092102112122 unmodified lines2152162172182192202212222232242252262272282 unmodified linesfrom PIL import Imagefrom huggingface_hub import InferenceClientimport osfrom gradio_client import Client# Set page configurationst.set_page_config(7 unmodified linesst.markdown("""<style>/* Main layout */.main { background-color: #f5f7fa; }/* Title styling */.title h1 {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;text-align: center;color: #007ACC; /* Changed to blue */font-size: 3rem;margin-bottom: 20px;}/* Image styling */.st-image img {border-radius: 15px;margin-bottom: 20px;max-width: 100%;}/* Sidebar styling */[data-testid="stSidebar"] {background-color: #ffffff; /* Changed to white */border-right: 1px solid #e6e6e6;}[data-testid="stSidebar"] .css-ng1t4o { color: #333333; }[data-testid="stSidebar"] .css-1d391kg { color: #333333; }/* File uploader styling */.stFileUploader {border: 2px dashed #007ACC; /* Changed to blue */border-radius: 10px;padding: 20px;text-align: center;color: #007ACC; /* Changed to blue */background-color: #ffffff;font-weight: bold;}/* File uploader hover effect */.stFileUploader:hover {background-color: #e6f2ff; /* Light blue hover effect */}/* Button styling */.stButton>button {background-color: #007ACC; /* Changed to blue */color: white;border: none;padding: 0.7rem 1.5rem;border-radius: 5px;font-size: 1.1rem;font-weight: bold;margin-top: 10px;cursor: pointer;}.stButton>button:hover {background-color: #005a99; /* Darker blue on hover */color: white;}/* Headers styling */h2 {color: #007ACC; /* Changed to blue */margin-top: 30px;font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}h3 {color: #007ACC; /* Changed to blue */font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}/* Text styling */.stMarkdown p { font-size: 1.1rem; color: #333333; }/* Footer styling */footer { visibility: hidden; }/* Hide sidebar on small screens */@media only screen and (max-width: 600px) {[data-testid="stSidebar"] { display: none; }.main .block-container { padding-left: 1rem; padding-right: 1rem; }.title h1 { font-size: 2rem; }.stButton>button { width: 100%; }}/* Sample images grid */.sample-images {display: flex;justify-content: center;flex-wrap: wrap;gap: 10px;}.sample-images img {width: 150px;height: 150px;object-fit: cover;border-radius: 10px;cursor: pointer;border: 2px solid transparent;}.sample-images img:hover {border: 2px solid #007ACC; /* Changed to blue */}</style>""", unsafe_allow_html=True)# Hugging Face API keyAPI_KEY = st.secrets["HF_API_KEY"]27 unmodified linesexcept Exception as e:return f"Error generating ingredients: {e}"# Main contentst.markdown('<div class="title"><h1>DelishAI - Your Culinary Assistant</h1></div>', unsafe_allow_html=True)10 unmodified linesst.markdown("---")st.markdown("<p style='text-align: center;'>Developed by Muhammad Hassan Butt.</p>", unsafe_allow_html=True)# Sample imagesst.subheader("Or try one of these sample images:")sample_images = {"Burger": "sample_images/burger.jpg","Pizza": "sample_images/pizza.jpg","Sushi": "sample_images/sushi.jpg","Salad": "sample_images/salad.jpg"}cols = st.columns(len(sample_images))for idx, (name, file_path) in enumerate(sample_images.items()):with cols[idx]:19 unmodified lines# Display only the top predictiontop_food = predictions[0]['label']st.header(f"🍽️ Food: {top_food}")# Generate and display ingredients for the top predictionst.subheader("📝 Ingredients")try:2 unmodified linesexcept Exception as e:st.error(f"Error generating ingredients: {e}")st.subheader("💡 Healthier Alternatives")try:client_gradio = Client("https://8a56cb969da1f9d721.gradio.live/")result = client_gradio.predict(query=f"What's a healthy {top_food} recipe, and why is it healthy?", api_name="/get_response")st.write(result)except Exception as e:st.error(f"Unable to contact RAG: {e}")else:st.info("Please select or upload an image to get started.")2 unmodified lines34567897 unmodified lines1718192021222324252627282927 unmodified lines57585960616263646510 unmodified lines7677787980818283848586878819 unmodified lines1081091101111121131142 unmodified lines1171181191201211221231241251261271281291301311321331341351361371381391401411421432 unmodified linesfrom PIL import Imagefrom huggingface_hub import InferenceClientimport osimport openai # Added import# Set page configurationst.set_page_config(7 unmodified linesst.markdown("""<style>/* [Your existing CSS styles here] */</style>""", unsafe_allow_html=True)local_css() # Apply the CSS# Hugging Face API keyAPI_KEY = st.secrets["HF_API_KEY"]27 unmodified linesexcept Exception as e:return f"Error generating ingredients: {e}"# **Set OpenAI API Key**openai.api_key = st.secrets["openai"]["api_key"] # Ensure you have this in your secrets# Main contentst.markdown('<div class="title"><h1>DelishAI - Your Culinary Assistant</h1></div>', unsafe_allow_html=True)10 unmodified linesst.markdown("---")st.markdown("<p style='text-align: center;'>Developed by Muhammad Hassan Butt.</p>", unsafe_allow_html=True)# Assuming `sample_images` is defined somewhere in your codesample_images = {"Pizza": "path_to_pizza_image.jpg","Salad": "path_to_salad_image.jpg",# Add more sample images as needed}cols = st.columns(len(sample_images))for idx, (name, file_path) in enumerate(sample_images.items()):with cols[idx]:19 unmodified lines# Display only the top predictiontop_food = predictions[0]['label']st.header(f"🍽️ Food: {top_food}")# Generate and display ingredients for the top predictionst.subheader("📝 Ingredients")try:2 unmodified linesexcept Exception as e:st.error(f"Error generating ingredients: {e}")# **Healthier Alternatives using OpenAI API**st.subheader("💡 Healthier Alternatives")try:response = openai.ChatCompletion.create(model="gpt-4o", # You can choose the model you prefermessages=[{"role": "system","content": "You are a helpful assistant specializing in providing healthy alternatives to various dishes."},{"role": "user","content": f"What's a healthy {top_food} recipe, and why is it healthy?"}],max_tokens=200, # Adjust as neededtemperature=0.7, # Adjust creativity level as needed)result = response['choices'][0]['message']['content'].strip()st.write(result)except Exception as e:st.error(f"Unable to generate healthier alternatives: {e}")else:st.info("Please select or upload an image to get started.")
app.py+30-115