Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +43 -0
- kaloriedata.csv +11 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="WebKalorier")
|
| 7 |
+
|
| 8 |
+
st.title("🍽️ WebKalorier – Kalorieestimering via Billede")
|
| 9 |
+
|
| 10 |
+
@st.cache_resource(show_spinner=False)
|
| 11 |
+
def get_classifier():
|
| 12 |
+
return pipeline("image-classification", model="eslamxm/vit-base-food101")
|
| 13 |
+
|
| 14 |
+
classifier = get_classifier()
|
| 15 |
+
|
| 16 |
+
# Load calorie data
|
| 17 |
+
df = pd.read_csv("kaloriedata.csv")
|
| 18 |
+
food_list = df["navn"].tolist()
|
| 19 |
+
|
| 20 |
+
uploaded_file = st.file_uploader("Upload et billede af din mad", type=["jpg","jpeg","png"])
|
| 21 |
+
if uploaded_file:
|
| 22 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 23 |
+
st.image(image, caption="Analyserer...", use_column_width=True)
|
| 24 |
+
with st.spinner("Klassificerer billede..."):
|
| 25 |
+
results = classifier(image, top_k=3)
|
| 26 |
+
# Display top result
|
| 27 |
+
top = results[0]
|
| 28 |
+
label = top["label"]
|
| 29 |
+
score = top["score"]
|
| 30 |
+
st.markdown(f"**Modelgæt:** {label} ({score*100:.1f}% sikkerhed)")
|
| 31 |
+
if score < 0.7:
|
| 32 |
+
chosen = st.selectbox("Modellen er usikker – vælg fødevare manuelt:", food_list)
|
| 33 |
+
else:
|
| 34 |
+
# Fuzzy matching could be added via utils/matcher.py
|
| 35 |
+
chosen = label.replace('_', ' ').lower()
|
| 36 |
+
gram = st.number_input(f"Hvor mange gram {chosen}?", min_value=1, max_value=2000, value=100)
|
| 37 |
+
kcal_per_100g = float(df.loc[df['navn']==chosen, 'kcal_pr_100g'].squeeze()) if chosen in df['navn'].values else 0
|
| 38 |
+
kcal = gram * kcal_per_100g / 100
|
| 39 |
+
st.markdown("### Analyse af måltid")
|
| 40 |
+
st.write(f"- {gram} g **{chosen}** = {kcal:.1f} kcal")
|
| 41 |
+
feedback = st.text_input("Har du feedback eller rettelse?")
|
| 42 |
+
if st.button("Send feedback"):
|
| 43 |
+
st.success("Tak for din feedback!")
|
kaloriedata.csv
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
navn,kcal_pr_100g
|
| 2 |
+
æg,155
|
| 3 |
+
kartoffel,77
|
| 4 |
+
smør,717
|
| 5 |
+
broccoli,35
|
| 6 |
+
salat,15
|
| 7 |
+
tomat,18
|
| 8 |
+
ris,130
|
| 9 |
+
pasta,131
|
| 10 |
+
kylling,239
|
| 11 |
+
æble,52
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
pillow
|
| 5 |
+
pandas
|