Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,64 +23,67 @@ def load_model():
|
|
| 23 |
|
| 24 |
model = load_model()
|
| 25 |
|
| 26 |
-
# ---
|
| 27 |
st.title("π½οΈ NutriDetect: AI Nutrition Companion")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
st.
|
| 33 |
-
st.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
**NutriDetect** is an AI-powered food recognition system developed to simplify dietary assessment and support healthier eating habits.
|
| 85 |
|
| 86 |
This project was accepted at the **ACM Conference**, showcasing innovation in AI-powered nutritional informatics.
|
|
@@ -95,17 +98,17 @@ NutriDetect uses the YOLOv8 object detection model trained on over 55,000 curate
|
|
| 95 |
|
| 96 |
### π§ Why It Matters
|
| 97 |
|
| 98 |
-
- Enables quick and accurate food recognition
|
| 99 |
-
- Designed for mobile, AR, and wearable integration
|
| 100 |
- Built with a culturally diverse dataset for global usage
|
| 101 |
|
| 102 |
---
|
| 103 |
|
| 104 |
### π¬ Research Highlights
|
| 105 |
|
| 106 |
-
- mAP@50 of **75.9%**
|
| 107 |
-
- Precision of **72.4%**
|
| 108 |
-
- Trained on NVIDIA RTX 4060 (8GB VRAM)
|
| 109 |
- Dataset curated from UECFOOD256, OID, and more
|
| 110 |
|
| 111 |
*NutriDetect is a step toward smarter, AI-powered food logging and healthcare.*
|
|
|
|
| 23 |
|
| 24 |
model = load_model()
|
| 25 |
|
| 26 |
+
# --- LAYOUT ---
|
| 27 |
st.title("π½οΈ NutriDetect: AI Nutrition Companion")
|
| 28 |
+
|
| 29 |
+
col_nav, col_main = st.columns([1, 5]) # Navigation on the left
|
| 30 |
+
|
| 31 |
+
with col_nav:
|
| 32 |
+
st.markdown("### π Menu")
|
| 33 |
+
page = st.radio("", ["Home", "Try It", "About"])
|
| 34 |
+
|
| 35 |
+
with col_main:
|
| 36 |
+
if page == "Home":
|
| 37 |
+
st.image("back_image.png", width=800)
|
| 38 |
+
st.markdown("""
|
| 39 |
+
Welcome to **NutriDetect** β detect food items from images using a custom-trained YOLOv8 model.
|
| 40 |
+
|
| 41 |
+
- π· Upload food images
|
| 42 |
+
- π§ Detect with YOLO
|
| 43 |
+
- β‘ Built for mobile and real-time use
|
| 44 |
+
""")
|
| 45 |
+
|
| 46 |
+
elif page == "Try It":
|
| 47 |
+
st.header("π Try Food Detection")
|
| 48 |
+
uploaded_file = st.file_uploader("Upload a food image", type=["jpg", "jpeg", "png"])
|
| 49 |
+
|
| 50 |
+
if uploaded_file:
|
| 51 |
+
img_id = str(uuid.uuid4()) + ".jpg"
|
| 52 |
+
image_path = os.path.join(TEMP_IMAGE_DIR, img_id)
|
| 53 |
+
with open(image_path, "wb") as f:
|
| 54 |
+
f.write(uploaded_file.read())
|
| 55 |
+
st.image(image_path, caption="Uploaded Image", width=400)
|
| 56 |
+
|
| 57 |
+
if st.button("π Detect Food"):
|
| 58 |
+
with st.spinner("Detecting..."):
|
| 59 |
+
results = model.predict(source=image_path, save=True, save_txt=False)
|
| 60 |
+
|
| 61 |
+
# Find the latest result image
|
| 62 |
+
detect_dir = "runs/detect"
|
| 63 |
+
all_preds = sorted(os.listdir(detect_dir), key=lambda x: os.path.getmtime(os.path.join(detect_dir, x)))
|
| 64 |
+
latest_run = os.path.join(detect_dir, all_preds[-1])
|
| 65 |
+
pred_image_path = os.path.join(latest_run, img_id)
|
| 66 |
+
|
| 67 |
+
if os.path.exists(pred_image_path):
|
| 68 |
+
st.image(pred_image_path, caption="Detection Result", width=800)
|
| 69 |
+
else:
|
| 70 |
+
st.warning("Prediction image not found.")
|
| 71 |
+
|
| 72 |
+
boxes = results[0].boxes
|
| 73 |
+
names = model.names
|
| 74 |
+
st.subheader("π Detected Items")
|
| 75 |
+
if len(boxes) == 0:
|
| 76 |
+
st.warning("No objects detected.")
|
| 77 |
+
else:
|
| 78 |
+
for box in boxes:
|
| 79 |
+
class_id = int(box.cls)
|
| 80 |
+
conf = float(box.conf)
|
| 81 |
+
label = names[class_id]
|
| 82 |
+
st.markdown(f"- **{label}** (Confidence: {conf:.2f})")
|
| 83 |
+
|
| 84 |
+
elif page == "About":
|
| 85 |
+
st.header("π About NutriDetect")
|
| 86 |
+
st.markdown("""
|
| 87 |
**NutriDetect** is an AI-powered food recognition system developed to simplify dietary assessment and support healthier eating habits.
|
| 88 |
|
| 89 |
This project was accepted at the **ACM Conference**, showcasing innovation in AI-powered nutritional informatics.
|
|
|
|
| 98 |
|
| 99 |
### π§ Why It Matters
|
| 100 |
|
| 101 |
+
- Enables quick and accurate food recognition
|
| 102 |
+
- Designed for mobile, AR, and wearable integration
|
| 103 |
- Built with a culturally diverse dataset for global usage
|
| 104 |
|
| 105 |
---
|
| 106 |
|
| 107 |
### π¬ Research Highlights
|
| 108 |
|
| 109 |
+
- mAP@50 of **75.9%**
|
| 110 |
+
- Precision of **72.4%**
|
| 111 |
+
- Trained on NVIDIA RTX 4060 (8GB VRAM)
|
| 112 |
- Dataset curated from UECFOOD256, OID, and more
|
| 113 |
|
| 114 |
*NutriDetect is a step toward smarter, AI-powered food logging and healthcare.*
|