Skip to content

Commit c0364c3

Browse files
committed
⚡ Initial Commit
0 parents  commit c0364c3

12 files changed

+5867
-0
lines changed

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Module",
9+
"type": "python",
10+
"request": "launch",
11+
"module": "streamlit",
12+
"args": ["run", "${file}"]
13+
}
14+
]
15+
}

FV.h5

11.2 MB
Binary file not shown.

Fruit_Veg_Classification_Mobilenet.ipynb

+5,636
Large diffs are not rendered by default.

Fruits_Vegetable_Classification.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import streamlit as st
2+
from PIL import Image
3+
from keras.preprocessing.image import load_img,img_to_array
4+
import numpy as np
5+
from keras.models import load_model
6+
import requests
7+
from bs4 import BeautifulSoup
8+
9+
model = load_model('FV.h5')
10+
labels = {0: 'apple', 1: 'banana', 2: 'beetroot', 3: 'bell pepper', 4: 'cabbage', 5: 'capsicum', 6: 'carrot', 7: 'cauliflower', 8: 'chilli pepper', 9: 'corn', 10: 'cucumber', 11: 'eggplant', 12: 'garlic', 13: 'ginger', 14: 'grapes', 15: 'jalepeno', 16: 'kiwi', 17: 'lemon', 18: 'lettuce',
11+
19: 'mango', 20: 'onion', 21: 'orange', 22: 'paprika', 23: 'pear', 24: 'peas', 25: 'pineapple', 26: 'pomegranate', 27: 'potato', 28: 'raddish', 29: 'soy beans', 30: 'spinach', 31: 'sweetcorn', 32: 'sweetpotato', 33: 'tomato', 34: 'turnip', 35: 'watermelon'}
12+
13+
fruits = ['Apple','Banana','Bello Pepper','Chilli Pepper','Grapes','Jalepeno','Kiwi','Lemon','Mango','Orange','Paprika','Pear','Pineapple','Pomegranate','Watermelon']
14+
vegetables = ['Beetroot','Cabbage','Capsicum','Carrot','Cauliflower','Corn','Cucumber','Eggplant','Ginger','Lettuce','Onion','Peas','Potato','Raddish','Soy Beans','Spinach','Sweetcorn','Sweetpotato','Tomato','Turnip']
15+
16+
def fetch_calories(prediction):
17+
try:
18+
url = 'https://www.google.com/search?&q=calories in ' + prediction
19+
req = requests.get(url).text
20+
scrap = BeautifulSoup(req, 'html.parser')
21+
calories = scrap.find("div", class_="BNeawe iBp4i AP7Wnd").text
22+
return calories
23+
except Exception as e:
24+
st.error("Can't able to fetch the Calories")
25+
print(e)
26+
27+
def processed_img(img_path):
28+
img=load_img(img_path,target_size=(224,224,3))
29+
img=img_to_array(img)
30+
img=img/255
31+
img=np.expand_dims(img,[0])
32+
answer=model.predict(img)
33+
y_class = answer.argmax(axis=-1)
34+
print(y_class)
35+
y = " ".join(str(x) for x in y_class)
36+
y = int(y)
37+
res = labels[y]
38+
print(res)
39+
return res.capitalize()
40+
41+
def run():
42+
st.title("Fruits🍍-Vegetable🍅 Classification")
43+
img_file = st.file_uploader("Choose an Image", type=["jpg", "png"])
44+
if img_file is not None:
45+
img = Image.open(img_file).resize((250,250))
46+
st.image(img,use_column_width=False)
47+
save_image_path = './uploads/'+img_file.name
48+
with open(save_image_path, "wb") as f:
49+
f.write(img_file.getbuffer())
50+
51+
# if st.button("Predict"):
52+
if img_file is not None:
53+
result= processed_img(save_image_path)
54+
print(result)
55+
if result in vegetables:
56+
st.info('**Category : Vegetables**')
57+
else:
58+
st.info('**Category : Fruit**')
59+
st.success("**Predicted : "+result+'**')
60+
cal = fetch_calories(result)
61+
if cal:
62+
st.warning('**'+cal+'(100 grams)**')
63+
run()

README.md

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
<p align="center">
3+
<img align= "center" src="https://drive.google.com/uc?export=view&id=1WgZHCHX8LbjJODPuKHmz_QgTqYGi50Yo" style=" align: center ; width: 650px; height: 320px" title="Akshat Sachan" />
4+
5+
</p>
6+
7+
8+
<h1 align="center">Welcome to Fruits🍍-Vegetables🍅 Classification ML Web-App 👋</h1>
9+
<p>
10+
<img alt="Version" src="https://img.shields.io/badge/version-0.1.0-blue.svg?cacheSeconds=2592000" />
11+
<a href="to be added" target="_blank">
12+
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
13+
</a>
14+
<a href="nonee" target="_blank">
15+
<img alt="License: MIT " src="https://img.shields.io/badge/License-MIT-yellow.svg" />
16+
</a>
17+
</p>
18+
19+
> Fruits🍍-Vegetables🍅 Classification
20+
21+
## APP PREVIEW
22+
23+
<p align="center">
24+
<img src="./sc1.PNG" alt="accessibility text">
25+
<img src="./sc2.PNG" title="hover text">
26+
27+
</p>
28+
29+
## Install
30+
31+
```sh
32+
pip install -r requirements.txt
33+
```
34+
35+
## Usage
36+
37+
- Clone my repository.
38+
- Open CMD in working directory.
39+
- Run following command.
40+
41+
```
42+
pip install -r requirements.txt
43+
```
44+
- `Fruits_Vegetable_Classification.py` is the main Python file of Streamlit Web-Application.
45+
- `Fruit_Veg_Classification_Mobilenet.ipynb` is the Notebook file of the Training
46+
- Dataset that I have used is [Fruit and Vegetable Image Recognition](https://www.kaggle.com/kritikseth/fruit-and-vegetable-image-recognition).
47+
48+
49+
## Run
50+
51+
```sh
52+
streamlit run Fruits_Vegetable_Classification.py
53+
```
54+
55+
56+
57+
58+
<div align="center">
59+
<img src="https://img.shields.io/badge/Contributors-seashell?logo=Microsoft%20Teams&style=for-the-badge" />
60+
</div>
61+
<br>
62+
63+
64+
<div align="center">
65+
<table>
66+
<tr align="center">
67+
68+
<td>
69+
70+
👤 **Akshat Sachan**
71+
72+
<p align="center">
73+
<img src = "https://avatars.githubusercontent.com/cryptocoderas" height="120" alt="Akshat Sachan">
74+
</p>
75+
<p align="center">
76+
<a href = "https://github.com/cryptocoderas">
77+
<img src = "http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
78+
width="36" height = "36"/></a>
79+
<a href = "https://www.linkedin.com/in/akshat-sachan-58b2921ab/">
80+
<img src = "http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg" width="36" height="36"/>
81+
</a>
82+
</p>
83+
</td>
84+
85+
86+
</table>
87+
</tr>
88+
</div>
89+
<br>
90+
91+
92+
<div align="center">
93+
<img src="https://img.shields.io/badge/Please%20'star',%20if%20you%20like%20it-blue?logo=Starship&style=for-the-badge" width="300" height="35"/>
94+
</div>
95+
96+
## Show your support
97+
98+
Give a ⭐️ if you liked this project or it helped you!
99+
100+
## 📝 License
101+
102+
Copyright © 2021 [Akshat Sachan](https://github.com/CryptocoderAS)<br />
103+
This project is [MIT](none) licensed.
104+
105+
## MIT License
106+
107+
```
108+
109+
Copyright (c) 2021 AKSHAT SACHAN
110+
111+
Permission is hereby granted, free of charge, to any person obtaining a copy
112+
of this software and associated documentation files (the "Software"), to deal
113+
in the Software without restriction, including without limitation the rights
114+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
115+
copies of the Software, and to permit persons to whom the Software is
116+
furnished to do so, subject to the following conditions:
117+
118+
The above copyright notice and this permission notice shall be included in all
119+
copies or substantial portions of the Software.
120+
121+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
122+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
123+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
124+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
125+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
126+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
127+
SOFTWARE.
128+
```
129+

STREAMLIT/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import streamlit as st
2+
st.write("Hello from Streamlit")

launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Streamlit",
9+
"type": "python",
10+
"request": "launch",
11+
"module": "streamlit.cli",
12+
"args": ["run", "${file}"]
13+
}
14+
]
15+
}

requirements.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
requests
2+
beautifulsoup4
3+
streamlit
4+
numpy
5+
Pillow
6+
keras~=2.6.0
7+
tensorflow~=2.8.0

sc1.PNG

206 KB
Loading

sc2.PNG

115 KB
Loading

uploads/Potato-for-Babies-scaled.jpg

64.1 KB
Loading

uploads/download.jpg

9.88 KB
Loading

0 commit comments

Comments
 (0)