Spaces:
Sleeping
Sleeping
Commit ·
55ca203
1
Parent(s): cf48067
Im strugglign
Browse files2 unmodified lines345667897 unmodified lines17181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211222021222324252627282927 unmodified lines57585960616263646510 unmodified lines7677781761777980179180181182818283848586878819 unmodified lines1081091102091111121131142 unmodified lines1171181191201211222202212221231241251261271281291301311321331341351361371381391402261411421432 unmodified linesfrom PIL import Imagefrom huggingface_hub import InferenceClientimport osfrom gradio_client import Clientimport openai # Added import
# Set page configurationst.set_page_config(7 unmodified lines st.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 */ } /* [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 lines except 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 lines st.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:")# Assuming `sample_images` is defined somewhere in your codesample_images = { "Burger": "sample_images/burger.jpg", "Pizza": "sample_images/pizza.jpg", "Sushi": "sample_images/sushi.jpg", "Salad": "sample_images/salad.jpg" "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 prediction top_food = predictions[0]['label'] st.header(f"🍽️ Food: {top_food}") # Generate and display ingredients for the top prediction st.subheader("📝 Ingredients") try:2 unmodified lines except Exception as e: st.error(f"Error generating ingredients: {e}")
# **Healthier Alternatives using OpenAI API** 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" response = openai.ChatCompletion.create( model="gpt-4o", # You can choose the model you prefer messages=[ { "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 needed temperature=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 contact RAG: {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