Spaces:
Sleeping
Sleeping
Commit ·
df033c3
1
Parent(s): 07326b1
Im strugglign
Browse files18 unmodified lines1920212223242526272 unmodified lines303132333435363738394041424344454647484950514 unmodified lines565758596061626364659 unmodified lines7576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311413 unmodified lines1281291301311321331341357 unmodified lines1431441451461471481491501511521531541551561571581591601613 unmodified lines16516616716816917017117217324 unmodified lines1981992002012022032043 unmodified lines2082092102112122132142152162172182192202212 unmodified lines2242252262272282292302312322332346 unmodified lines24124224324424524624724824925025125218 unmodified lines"""<style>/* Main layout */.main {background-color: #f0f2f6;}/* Title styling */.title h1 {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;2 unmodified linesfont-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: #ff4b4b;}[data-testid="stSidebar"] .css-ng1t4o {color: white;}[data-testid="stSidebar"] .css-1d391kg {color: white;}/* File uploader styling */.stFileUploader {border: 2px dashed #ff4b4b;4 unmodified linesbackground-color: #ffffff;font-weight: bold;}/* File uploader hover effect */.stFileUploader:hover {background-color: #ffe5e5;}/* Button styling */.stButton>button {background-color: #ff4b4b;9 unmodified linesbackground-color: #e04343;color: white;}/* Headers styling */h2 {color: #ff4b4b;margin-top: 30px;font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}h3 {color: #ff4b4b;font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}/* Text styling */.stMarkdown p {font-size: 1.1rem;}/* 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;13 unmodified linesborder: 2px solid #ff4b4b;}</style>""",unsafe_allow_html=True)local_css()7 unmodified lines# Load the image classification pipeline@st.cache_resourcedef load_image_classification_pipeline():"""Load the image classification pipeline using a pretrained model."""return pipeline("image-classification", model="Shresthadev403/food-image-classification")pipe_classification = load_image_classification_pipeline()# Function to generate ingredients using Hugging Face Inference Clientdef get_ingredients_qwen(food_name):"""Generate a list of ingredients for the given food item using Qwen NLP model.Returns a clean, comma-separated list of ingredients."""messages = [{"role": "user",3 unmodified lines]try:completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct",messages=messages,max_tokens=50)generated_text = completion.choices[0].message["content"].strip()return generated_text24 unmodified lines"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]:3 unmodified lines# File uploaderst.subheader("Upload a food image:")uploaded_file = st.file_uploader("", type=["jpg", "png", "jpeg"])if 'uploaded_file' in locals() and uploaded_file is not None:# Display the uploaded imageif isinstance(uploaded_file, str):# Sample image selectedimage = Image.open(uploaded_file)else:# User uploaded imageimage = Image.open(uploaded_file)st.image(image, caption="Uploaded Image", use_container_width=True)2 unmodified lineswith st.spinner("Classifying..."):# Make predictionspredictions = pipe_classification(image)# 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:6 unmodified linestry: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.")18 unmodified lines19202122232425262 unmodified lines2930313233343536373839404142434445464748494 unmodified lines5455565758596061626364659 unmodified lines7576777879808182838485868788899091929394959697989913 unmodified lines1131141151161171181197 unmodified lines1271281291301311321331341351361371381391403 unmodified lines14414514614714814915024 unmodified lines1751761771781791803 unmodified lines1841851861871881891901911921931942 unmodified lines1971981992002012022032042052066 unmodified lines21321421521621721821922022122218 unmodified lines"""<style>/* Main layout */.main { background-color: #f0f2f6; }/* Title styling */.title h1 {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;2 unmodified linesfont-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: #ff4b4b;}[data-testid="stSidebar"] .css-ng1t4o { color: white; }[data-testid="stSidebar"] .css-1d391kg { color: white; }/* File uploader styling */.stFileUploader {border: 2px dashed #ff4b4b;4 unmodified linesbackground-color: #ffffff;font-weight: bold;}/* File uploader hover effect */.stFileUploader:hover {background-color: #ffe5e5;}/* Button styling */.stButton>button {background-color: #ff4b4b;9 unmodified linesbackground-color: #e04343;color: white;}/* Headers styling */h2 { color: #ff4b4b; margin-top: 30px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }h3 { color: #ff4b4b; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }/* Text styling */.stMarkdown p { font-size: 1.1rem; }/* 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;13 unmodified linesborder: 2px solid #ff4b4b;}</style>""", unsafe_allow_html=True)local_css()7 unmodified lines# Load the image classification pipeline@st.cache_resourcedef load_image_classification_pipeline():""" Load the image classification pipeline using a pretrained model. """return pipeline("image-classification", model="Shresthadev403/food-image-classification")pipe_classification = load_image_classification_pipeline()# Function to generate ingredients using Hugging Face Inference Clientdef get_ingredients_qwen(food_name):""" Generate a list of ingredients for the given food item using Qwen NLP model. Returns a clean, comma-separated list of ingredients. """messages = [{"role": "user",3 unmodified lines]try:completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, max_tokens=50)generated_text = completion.choices[0].message["content"].strip()return generated_text24 unmodified lines"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]:3 unmodified lines# File uploaderst.subheader("Upload a food image:")uploaded_file = st.file_uploader("", type=["jpg", "png", "jpeg"])if 'uploaded_file' in locals() and uploaded_file is not None:# Display the uploaded imageif isinstance(uploaded_file, str): # Sample image selectedimage = Image.open(uploaded_file)else: # User uploaded imageimage = Image.open(uploaded_file)st.image(image, caption="Uploaded Image", use_container_width=True)2 unmodified lineswith st.spinner("Classifying..."):# Make predictionspredictions = pipe_classification(image)# 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:6 unmodified linestry: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.")
app.py+30-60