<s> import cherrypy , os , urllib , pickle <EOL> from numpy import * <EOL> from PCV . imagesearch import imagesearch <EOL> """<STR_LIT>""" <EOL> class SearchDemo : <EOL> def __init__ ( self ) : <EOL> f = open ( '<STR_LIT>' ) <EOL> self . imlist = f . readlines ( ) <EOL> f . close ( ) <EOL> self . nbr_images = len ( self . imlist ) <EOL> self . ndx = range ( self . nbr_images ) <EOL> f = open ( '<STR_LIT>' , '<STR_LIT:rb>' ) <EOL> self . voc = pickle . load ( f ) <EOL> f . close ( ) <EOL> self . maxres = <NUM_LIT:15> <EOL> self . header = """<STR_LIT>""" <EOL> self . footer = """<STR_LIT>""" <EOL> def index ( self , query = None ) : <EOL> self . src = imagesearch . Searcher ( '<STR_LIT>' , self . voc ) <EOL> html = self . header <EOL> html += """<STR_LIT>""" <EOL> if query : <EOL> res = self . src . query ( query ) [ : self . maxres ] <EOL> for dist , ndx in res : <EOL> imname = self . src . get_filename ( ndx ) <EOL> html += "<STR_LIT>" + imname + "<STR_LIT>" <EOL> html += "<STR_LIT>" + imname + "<STR_LIT>" <EOL> html += "<STR_LIT>" <EOL> else : <EOL> random . shuffle ( self . ndx ) <EOL> for i in self . ndx [ : self . maxres ] : <EOL> imname = self . imlist [ i ] <EOL> html += "<STR_LIT>" + imname + "<STR_LIT>" <EOL> html += "<STR_LIT>" + imname + "<STR_LIT>" <EOL> html += "<STR_LIT>" <EOL> html += self . footer <EOL> return html <EOL> index . exposed = True <EOL> cherrypy . quickstart ( SearchDemo ( ) , '<STR_LIT:/>' , config = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) </s>
