Skip to content

Instantly share code, notes, and snippets.

@silverNitrateIon
Created June 19, 2018 21:59
Show Gist options
  • Save silverNitrateIon/fad0d7080e7d8afdff488312f573d1b3 to your computer and use it in GitHub Desktop.
Save silverNitrateIon/fad0d7080e7d8afdff488312f573d1b3 to your computer and use it in GitHub Desktop.
from tkinter import *
from watson_developer_cloud import VisualRecognitionV3
import json
import os
#invoking tkinkter as root
root = Tk()
#Setting up input, has to be up here since it is invoked below
Label(root, text="Enter File Name With Extension").pack()
user_data = Entry(root)
user_data.pack()
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
#Buttons in the program
self.CNN_run = Button(frame, text="Start", command=self.filescan)
self.CNN_run.pack(side=LEFT)
self.read_outfile = Button(frame, text="Read the Output", command=self.read_out)
self.read_outfile.pack(side=RIGHT)
#Defining the functions called in the buttons
def print_input(self):
print('./'+user_data.get())
def filescan(self):
visrec = VisualRecognitionV3(
'2018-03-19',
url='https://gateway.watsonplatform.net/visual-recognition/api',
iam_api_key='ysQKtXudc8Otf9UuAyZx9DAcOa0zHLNq-AQ9i2U5z6_k')
#Calling to IBM Watson's Image Recognition system
with open('./' + user_data.get(), 'rb') as images_file:
classes = visrec.classify(
images_file,
thereshold='0.6',
classifier_ids='DefaultCustomModel_1853365427')
#Printing the json file out to a text document
outfile = open("jsondump.txt", "w")
outfile.write(json.dumps(classes, indent=2))
outfile.close()
print(json.dumps(classes, indent=2))
def read_out(self):
os.system('open -a TextEdit jsondump.txt')
#Title and boilerplate for the program
app = App(root)
root.title("CNN Image Search - Alpha Version")
root.geometry("500x200")
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment