Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load a food classification pipeline
|
| 6 |
+
food_pipeline = pipeline(task="image-classification", model="microsoft/resnet-50")
|
| 7 |
+
|
| 8 |
+
st.title("Food Recognition Agent 🍕")
|
| 9 |
+
|
| 10 |
+
# Upload the image
|
| 11 |
+
file_name = st.file_uploader("Upload a food image")
|
| 12 |
+
|
| 13 |
+
if file_name is not None:
|
| 14 |
+
col1, col2 = st.columns(2)
|
| 15 |
+
|
| 16 |
+
# Display the uploaded image
|
| 17 |
+
image = Image.open(file_name)
|
| 18 |
+
col1.image(image, use_container_width=True, caption="Uploaded Image")
|
| 19 |
+
|
| 20 |
+
# Make predictions
|
| 21 |
+
predictions = food_pipeline(image)
|
| 22 |
+
|
| 23 |
+
# Display probabilities
|
| 24 |
+
col2.header("Food Predictions 🍽️")
|
| 25 |
+
for p in predictions:
|
| 26 |
+
col2.subheader(f"{p['label']}: {round(p['score'] * 100, 1)}%")
|