Skip to content

Commit 0e0960e

Browse files
committed
Updates to classify.py
1 parent 7b62042 commit 0e0960e

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

classify.py renamed to tensorpy/classify.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def download_and_classify_image(image_url):
1818
global images_classified
1919
if images_classified >= settings.MAX_IMAGES_PER_PAGE:
20-
return None
20+
return
2121
downloads_folder = settings.DOWNLOADS_FOLDER
2222

2323
# Prevent file conflicts by using unique identifiers
@@ -59,15 +59,13 @@ def download_and_classify_image(image_url):
5959
downloads_folder + "/temp_image_jpg.jpg")
6060
lock3.release()
6161

62-
return best_guess
6362

64-
65-
if __name__ == "__main__":
66-
expected_arg = "[PAGE(HTML) URL <OR> IMAGE(JPG/PNG) URL]"
63+
def main():
64+
expected_arg = "[PAGE_URL or IMAGE_URL]"
6765
num_args = len(sys.argv)
6866
if num_args < 2 or num_args > 2:
69-
print "Invalid Run Command! Usage:"
70-
print "python classify.py %s" % expected_arg
67+
print "\n* INVALID RUN COMMAND! * Usage:"
68+
print "classify %s\n" % expected_arg
7169
elif num_args == 2:
7270
url = sys.argv[1]
7371
valid_url = web_core.is_valid_url(url)
@@ -83,13 +81,13 @@ def download_and_classify_image(image_url):
8381
print(best_guess)
8482
print("")
8583
elif content_type == 'html':
84+
global images_classified
8685
image_list = image_base.get_all_images_on_page(url)
8786

8887
if 'linux2' not in sys.platform and settings.MAX_THREADS > 1:
8988
# Multi-threading the work when not using Docker Linux
9089
pool = ThreadPool(settings.MAX_THREADS)
91-
results_list = pool.map(
92-
download_and_classify_image, image_list)
90+
pool.map(download_and_classify_image, image_list)
9391
pool.close()
9492
pool.join()
9593
else:
@@ -125,3 +123,6 @@ def download_and_classify_image(image_url):
125123
else:
126124
raise Exception(
127125
"Unexpected content type %s. Fix the code!" % content_type)
126+
127+
if __name__ == "__main__":
128+
main()

0 commit comments

Comments
 (0)