Spaces:
Runtime error
Runtime error
ksvmuralidhar
commited on
Commit
•
1c0510f
1
Parent(s):
3c38139
Update app.py
Browse files
app.py
CHANGED
@@ -14,11 +14,15 @@ import zipfile
|
|
14 |
import logging
|
15 |
|
16 |
# unzip vegetable images
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
@st.cache_resource
|
22 |
class ImageVectorizer:
|
23 |
'''
|
24 |
Get vector representation of an image using VGG19 model fine tuned on vegetable images for classification
|
@@ -43,6 +47,7 @@ class ImageVectorizer:
|
|
43 |
test_image = np.array([test_image])
|
44 |
return model(test_image).numpy()[0]
|
45 |
|
|
|
46 |
@st.cache_resource
|
47 |
def get_milvus_collection():
|
48 |
uri = os.environ.get("URI")
|
@@ -102,14 +107,18 @@ def find_similar_images(img_path: str, top_n: int=15):
|
|
102 |
|
103 |
def delete_file(path_: str):
|
104 |
if os.path.exists(path_):
|
105 |
-
|
106 |
|
107 |
|
108 |
-
|
|
|
109 |
upload_file_path = os.path.join('.', 'uploads')
|
110 |
-
os.makedirs(upload_file_path, exist_ok=True)
|
111 |
upload_filename = "input.jpg"
|
112 |
upload_file_path = os.path.join(upload_file_path, upload_filename)
|
|
|
|
|
|
|
|
|
113 |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}
|
114 |
r = get(img_url, headers=headers)
|
115 |
with open(upload_file_path, "wb") as file:
|
|
|
14 |
import logging
|
15 |
|
16 |
# unzip vegetable images
|
17 |
+
def unzip_images():
|
18 |
+
with zipfile.ZipFile("Vegetable Images.zip", 'r') as zip_ref:
|
19 |
+
zip_ref.extractall('.')
|
20 |
+
logging.debug('unzipped images')
|
21 |
+
|
22 |
+
if not os.path.exists('Vegetable Images/'):
|
23 |
+
unzip_images()
|
24 |
+
|
25 |
|
|
|
26 |
class ImageVectorizer:
|
27 |
'''
|
28 |
Get vector representation of an image using VGG19 model fine tuned on vegetable images for classification
|
|
|
47 |
test_image = np.array([test_image])
|
48 |
return model(test_image).numpy()[0]
|
49 |
|
50 |
+
|
51 |
@st.cache_resource
|
52 |
def get_milvus_collection():
|
53 |
uri = os.environ.get("URI")
|
|
|
107 |
|
108 |
def delete_file(path_: str):
|
109 |
if os.path.exists(path_):
|
110 |
+
os.remove(path_)
|
111 |
|
112 |
|
113 |
+
@st.cache_resource
|
114 |
+
def get_upload_path():
|
115 |
upload_file_path = os.path.join('.', 'uploads')
|
|
|
116 |
upload_filename = "input.jpg"
|
117 |
upload_file_path = os.path.join(upload_file_path, upload_filename)
|
118 |
+
return upload_file_path
|
119 |
+
|
120 |
+
def process_input_image(img_url):
|
121 |
+
upload_file_path = get_upload_path()
|
122 |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}
|
123 |
r = get(img_url, headers=headers)
|
124 |
with open(upload_file_path, "wb") as file:
|