ksvmuralidhar commited on
Commit
1610241
·
verified ·
1 Parent(s): f6bc454

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -25
app.py CHANGED
@@ -16,7 +16,6 @@ import zipfile
16
  with zipfile.ZipFile("Vegetable Images.zip", 'r') as zip_ref:
17
  zip_ref.extractall('.')
18
 
19
- placeholder = st.empty()
20
 
21
  class ImageVectorizer:
22
  '''
@@ -119,27 +118,22 @@ def process_input_image(img_url):
119
  vectorizer = ImageVectorizer()
120
  collection = get_milvus_collection()
121
 
122
-
123
- def main():
124
- try:
125
- st.markdown("<h3>Find Similar Vegetable Images</h3>", unsafe_allow_html=True)
126
- desc = '''<p style="font-size: 15px;">Allowed Vegetables: Broad Bean, Bitter Gourd, Bottle Gourd,
127
- Green Round Brinjal, Broccoli, Cabbage, Capsicum, Carrot, Cauliflower, Cucumber,
128
- Raw Papaya, Potato, Green Pumpkin, Radish, Tomato.
129
- </p>
130
- <p style="font-size: 13px;">Image embeddings are extracted from a fine-tuned VGG model. The model is fine-tuned on <a href="https://www.kaggle.com/datasets/misrakahmed/vegetable-image-dataset" target="_blank">images</a> clicked using a mobile phone camera.
131
- Embeddings of 20,000 vegetable images are stored in Milvus vector database. Embeddings of the input image are computed and 15 most similar images (based on L2 distance) are displayed.</p>
132
- '''
133
- st.markdown(desc, unsafe_allow_html=True)
134
- img_url = st.text_input("Paste the image URL of a vegetable and hit Enter:", "")
135
- if img_url:
136
- placeholder.empty()
137
- img_path = process_input_image(img_url)
138
- find_similar_images(img_path, 15)
139
- delete_file(os.path.dirname(img_path))
140
- except Exception as e:
141
- st.error(f'An unexpected error occured: \n{e}')
142
-
143
-
144
- if __name__ == "__main__":
145
- main()
 
16
  with zipfile.ZipFile("Vegetable Images.zip", 'r') as zip_ref:
17
  zip_ref.extractall('.')
18
 
 
19
 
20
  class ImageVectorizer:
21
  '''
 
118
  vectorizer = ImageVectorizer()
119
  collection = get_milvus_collection()
120
 
121
+ try:
122
+ st.markdown("<h3>Find Similar Vegetable Images</h3>", unsafe_allow_html=True)
123
+ desc = '''<p style="font-size: 15px;">Allowed Vegetables: Broad Bean, Bitter Gourd, Bottle Gourd,
124
+ Green Round Brinjal, Broccoli, Cabbage, Capsicum, Carrot, Cauliflower, Cucumber,
125
+ Raw Papaya, Potato, Green Pumpkin, Radish, Tomato.
126
+ </p>
127
+ <p style="font-size: 13px;">Image embeddings are extracted from a fine-tuned VGG model. The model is fine-tuned on <a href="https://www.kaggle.com/datasets/misrakahmed/vegetable-image-dataset" target="_blank">images</a> clicked using a mobile phone camera.
128
+ Embeddings of 20,000 vegetable images are stored in Milvus vector database. Embeddings of the input image are computed and 15 most similar images (based on L2 distance) are displayed.</p>
129
+ '''
130
+ st.markdown(desc, unsafe_allow_html=True)
131
+ img_url = st.text_input("Paste the image URL of a vegetable and hit Enter:", "")
132
+ placeholder = st.empty()
133
+ if img_url:
134
+ placeholder.empty()
135
+ img_path = process_input_image(img_url)
136
+ find_similar_images(img_path, 15)
137
+ delete_file(os.path.dirname(img_path))
138
+ except Exception as e:
139
+ st.error(f'An unexpected error occured: \n{e}')