Kaludi commited on
Commit
b0af9aa
1 Parent(s): 01da06b

Upload 11 files

Browse files
.gitattributes CHANGED
@@ -32,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ examples/example_1.jpg filter=lfs diff=lfs merge=lfs -text
36
+ examples/example_6.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
- title: Food-Category-Classification V2 App
3
- emoji: 💩
4
- colorFrom: green
5
- colorTo: indigo
6
- sdk: streamlit
7
- sdk_version: 1.17.0
8
  app_file: app.py
9
  pinned: false
10
- license: openrail
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Food Category Classification V2 App
3
+ emoji: 🍳
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 3.0.24
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+
4
+ from transformers import pipeline
5
+ import numpy as np
6
+ from transformers import AutoFeatureExtractor
7
+ from transformers import AutoModelForImageClassification
8
+
9
+ st.set_page_config(layout='wide',
10
+ page_title='Food Category Classification & Recipes'
11
+ )
12
+
13
+ # Setting up Sidebar
14
+ social_acc = ['App Description', 'About Project']
15
+ social_acc_nav = st.sidebar.radio('**INFORMATION SECTION**', social_acc)
16
+
17
+ if social_acc_nav == 'App Description':
18
+ st.sidebar.markdown("<h2 style='text-align: center;'> Food Category Classification Description </h2> ", unsafe_allow_html=True)
19
+ st.sidebar.markdown("This is an updated Food Category Image Classifier model of the [old](https://huggingface.co/Kaludi/food-category-classification) model that has been trained by [Kaludi](https://huggingface.co/Kaludi) to recognize 12 different categories of foods, which includes **Bread**, **Dairy**, **Dessert**, **Egg**, **Fried Food**, **Fruit**, **Meat**, **Noodles**, **Rice**, **Seafood**, **Soup**, and **Vegetable**. It can accurately classify an image of food into one of these categories by analyzing its visual features. This model can be used by food bloggers, restaurants, and recipe websites to quickly categorize and sort their food images, making it easier to manage their content and provide a better user experience.")
20
+
21
+ elif social_acc_nav == 'About Project':
22
+ st.sidebar.markdown("<h2 style='text-align: center;'> About Project </h2>", unsafe_allow_html=True)
23
+ st.sidebar.markdown("<hr style='text-align: center;'>", unsafe_allow_html=True)
24
+ st.sidebar.markdown("<h3 style='text-align: center;'>Project Location:</h3>", unsafe_allow_html=True)
25
+ st.sidebar.markdown("<p style='text-align: center;'><strong><a href='https://github.com/Kaludii'>Model</a></strong> | <strong><a href='https://github.com/Kaludii'>Dataset</a></strong></p>", unsafe_allow_html=True)
26
+ st.sidebar.markdown("<hr style='text-align: center;'>", unsafe_allow_html=True)
27
+ st.sidebar.markdown("<h3 style='text-align: center;'>Project Creators:</h3>", unsafe_allow_html=True)
28
+ st.sidebar.markdown("<p style='text-align: center;'><a href='https://github.com/Kaludii'><strong>AA</strong></a></p>", unsafe_allow_html=True)
29
+ st.sidebar.markdown("<p style='text-align: center;'><a href='https://github.com/Kaludii'><strong>AM</strong></a></p>", unsafe_allow_html=True)
30
+ st.sidebar.markdown("<p style='text-align: center;'><a href='https://github.com/Kaludii'><strong>BK</strong></a></p>", unsafe_allow_html=True)
31
+ st.sidebar.markdown("<p style='text-align: center;'><a href='https://github.com/Kaludii'><strong>DK</strong></a></p>", unsafe_allow_html=True)
32
+
33
+
34
+ def main():
35
+ st.title("Food Category Classification & Recipes")
36
+
37
+ st.markdown("### Backgroud")
38
+ st.markdown("This is an updated Food Category Image Classifier model of the [old](https://huggingface.co/Kaludi/food-category-classification) model that has been trained by [Kaludi](https://huggingface.co/Kaludi) to recognize 12 different categories of foods, which includes **Bread**, **Dairy**, **Dessert**, **Egg**, **Fried Food**, **Fruit**, **Meat**, **Noodles**, **Rice**, **Seafood**, **Soup**, and **Vegetable**. It can accurately classify an image of food into one of these categories by analyzing its visual features. This model can be used by food bloggers, restaurants, and recipe websites to quickly categorize and sort their food images, making it easier to manage their content and provide a better user experience.")
39
+ st.header("Try it out!")
40
+
41
+ images = ["examples/example_0.jpg",
42
+ "examples/example_1.jpg",
43
+ "examples/example_2.jpg",
44
+ "examples/example_3.jpg",
45
+ "examples/example_4.jpg",
46
+ "examples/example_5.jpg",
47
+ "examples/example_6.jpg",
48
+ "examples/example_7.jpg"]
49
+ show_images = False
50
+ if st.button("Show/Hide Examples"):
51
+ show_images = not show_images
52
+ if show_images:
53
+ st.header("Example Images")
54
+ for image in images:
55
+ st.image(image, width=250)
56
+
57
+ uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg','jpg'])
58
+
59
+ if uploaded_file!=None:
60
+ img=Image.open(uploaded_file)
61
+
62
+ extractor = AutoFeatureExtractor.from_pretrained("Kaludi/food-category-classification-v2.0")
63
+ model = AutoModelForImageClassification.from_pretrained("Kaludi/food-category-classification-v2.0")
64
+
65
+ inputs = extractor(img,return_tensors="pt")
66
+ outputs = model(**inputs)
67
+ label_num=outputs.logits.softmax(1).argmax(1)
68
+ label_num=label_num.item()
69
+
70
+ probs = outputs.logits.softmax(dim=1)
71
+ percentage = round(probs[0, label_num].item() * 100, 2)
72
+
73
+ st.write("The prediction class is:")
74
+
75
+ if label_num==0:
76
+ st.write("Bread (" + f"{percentage}%)")
77
+ elif label_num==1:
78
+ st.write("Dairy (" + f"{percentage}%)")
79
+ elif label_num==2:
80
+ st.write("Dessert (" + f"{percentage}%)")
81
+ elif label_num==3:
82
+ st.write("Egg (" + f"{percentage}%)")
83
+ elif label_num==4:
84
+ st.write("Fried Food (" + f"{percentage}%)")
85
+ elif label_num==5:
86
+ st.write("Fruit (" + f"{percentage}%)")
87
+ elif label_num==6:
88
+ st.write("Meat (" + f"{percentage}%)")
89
+ elif label_num==7:
90
+ st.write("Noodles (" + f"{percentage}%)")
91
+ elif label_num==8:
92
+ st.write("Rice (" + f"{percentage}%)")
93
+ elif label_num==9:
94
+ st.write("Seafood (" + f"{percentage}%)")
95
+ elif label_num==10:
96
+ st.write("Soup (" + f"{percentage}%)")
97
+ else:
98
+ st.write("Vegetable (" + f"{percentage}%)")
99
+
100
+
101
+ select_health = st.selectbox("Select one:", ["Choose healthy or non-healthy", "Healthy", "Non-healthy"])
102
+ if select_health == "Healthy":
103
+ st.write("You selected healthy for", "Bread" if label_num==0 else "Dairy" if label_num==1 else "Dessert" if label_num==2 else "Egg" if label_num==3 else "Fried Food" if label_num==4 else "Fruit" if label_num==5 else "Meat" if label_num==6 else "Noodles" if label_num==7 else "Rice" if label_num==8 else "Seafood" if label_num==9 else "Soup" if label_num==10 else "Vegetable")
104
+ # Add code to fetch healthy recipe here
105
+ elif select_health == "Non-healthy":
106
+ st.write("You selected non-healthy for", "Bread" if label_num==0 else "Dairy" if label_num==1 else "Dessert" if label_num==2 else "Egg" if label_num==3 else "Fried Food" if label_num==4 else "Fruit" if label_num==5 else "Meat" if label_num==6 else "Noodles" if label_num==7 else "Rice" if label_num==8 else "Seafood" if label_num==9 else "Soup" if label_num==10 else "Vegetable")
107
+ # Add code to fetch unhealthy recipe here
108
+
109
+ st.image(img)
110
+
111
+ if __name__ == '__main__':
112
+ main()
examples/example_0.jpg ADDED
examples/example_1.jpg ADDED

Git LFS Details

  • SHA256: 88426cd1997ce978e1d804ead67c0965938f169b0d0ad7ba49f4bb08e32fb84e
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
examples/example_2.jpg ADDED
examples/example_3.jpg ADDED
examples/example_4.jpg ADDED
examples/example_5.jpg ADDED
examples/example_6.jpg ADDED

Git LFS Details

  • SHA256: 335b9440d0dbe067de593121fc9019ccb7267cb46aac9bd9cd6aa4cfbe010757
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
examples/example_7.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastai==2.7.4
2
+ huggingface_hub[fastai]
3
+ fastcore>=1.3.27
4
+ transformers