def gen_member_card(data): doc, tag, text = Doc().tagtext() with tag('li'): with tag('center'): with tag('a', id="memid", href=data['knc_id']): with tag('b', id="memid"): text(data['name']) doc._append("<br/>") # with tag('a', id="memid", href=data['knc_id']): # text(data['knc_id']) # doc._append("<br/>") text(data['role']) if 'pronouns' in data: text(' (%s)' % data['pronouns']) doc._append("<br/>") with tag('a', href='mailto:' + data['email']): text(data['email']) doc._append("<br/>") links_list = ['github', 'website', 'CV'] if any((x in data) for x in links_list): links_text_list = [] for x in links_list: if x in data: links_text_list.append('<a href="%s">%s<a>' % (data[x], x)) with tag('center'): doc._append(" | ".join(links_text_list)) doc._append("<br/>") if 'interests' in data: with tag('center'): with tag('p'): with tag('u'): text('Interests:') text(' ') text(data['interests']) return indent(doc.getvalue(), indent_text=False)
def gen_member_card(data): doc, tag, text = Doc().tagtext() with tag('li'): with tag('center'): with tag('b', id="memid"): text(data['name']) # if 'pronouns' in data: # text(' (%s)' % data['pronouns']) # else: # text(' (they/them)') doc._append("<br/>") with tag('a', id="memid", href=data['knc_id']): text(data['knc_id']) doc._append("<br/>") text(data['role']) doc._append("<br/>") with tag('a', href=data['email']): text(data['email']) doc._append("<br/>") links_list = ['github', 'website', 'CV'] if any((x in data) for x in links_list): with tag('center'): for x in links_list: if x in data: with tag('a', href=data[x]): text(x) doc._append("<br/>") if 'interests' in data: with tag('center'): with tag('p'): with tag('u'): text('Interests:') text(' ') text(data['interests']) return indent(doc.getvalue(), indent_text=False)
def generate_html_code(input1,input2,operations): doc,tag,text,line = Doc().ttl() with tag('html'): with tag('head'): doc._append('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">') doc._append('<script src="https://use.fontawesome.com/35ac922f38.js"></script>') with tag('body',klass = 'container bg-light'): line('h2','file difference',klass = 'text-center') with tag('div',klass = 'card'): ########3 line('h4', 'File A content = ' + input1) doc._append('<br>') line('h4', 'File B content = ' + input2) line('h6', 'You Can Convert A To B with these operations', klass='text-center display-4') with tag('div',klass = 'container'): for i in operations: if i[0:3] == 'ADD': with tag('div',klass = "bg-success"): line('i','',klass = 'fa fa-plus pull-right') line('h4',i[3:]) elif i[0:3] == 'REM': with tag('div',klass = "bg-danger"): line('i','',klass = 'fa fa-remove pull-right') line('h4',i[3:]) if i[0:3] == 'LCS': with tag('div',klass = "bg-info"): line('i','',klass = 'fa fa-star pull-right') line('h4',i[3:]) return indent(doc.getvalue())
def generateMarkUp(operations, A, B): doc, tag, text, line = Doc().ttl() with tag('html'): with tag('head'): doc._append( '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">' ) doc._append( '<script src="https://use.fontawesome.com/35ac922f38.js"></script>' ) with tag('body', klass='container bg-light'): line('h2', 'File Differ', klass='text-center display-2') with tag('div', klass='card'): with tag('div', klass='card-body'): line('h4', 'File A content = ' + A) doc._append('<br>') line('h4', 'File B content = ' + B) line('h6', 'You Can Convert A To B with these operations', klass='text-center display-4') with tag('div', klass='container'): for op in operations: if op[:3] == 'ADD': with tag('div', klass="bg-success"): line('i', '', klass="fa fa-plus mr-3 pull-right") line('h3', op[3:], klass="text-white ml-5") elif op[:3] == 'REM': with tag('div', klass="bg-danger"): line('i', '', klass="fa fa-remove mr-3 pull-right") line('h3', op[3:], klass="text-white ml-5") elif op[:3] == 'LCS': with tag('div', klass="bg-primary"): line('i', '', klass="fa fa-star mr-3 pull-right") line('h3', op[3:], klass="text-white ml-5") doc._append('<h6>Developed by github/Subhodeep and Shourya</h6>') return indent(doc.getvalue())
def gen_proj_card(data): user_info = load_user_info() doc, tag, text = Doc().tagtext() with tag('li'): with tag('a', id="proj_id", href='projects/' + data['proj_id']): text(data['projname']) doc._append("<br/>") with tag('b'): text('Contributors: ') u_idx = 0 for user in data['contributors']: if user[0] == '@': with tag('a', href=user): text(user_info[user]['name']) else: text(user) u_idx += 1 if u_idx < len(data['contributors']): text(', ') doc._append("<br/>") text(data['short_desc']) if 'thumbnail' in data: doc._append('<img src="%s" style="width: 25vw;">' % data['thumbnail']) doc._append("<br/><br/><br/>") return indent(doc.getvalue(), indent_text=False)
def allstates(): if (val[1] == "0"): tkMessageBox.showinfo("Please Correct", "Please choose your input image file first") elif (val[1] == "1"): parts = list(FaceParts.state()) print(parts, Alg) #Alg.get doc, tag, text = Doc().tagtext() doc.asis('<!DOCTYPE html>') with tag('html'): doc._append( '<head><link rel="stylesheet" type="text/css" href="theme.css"></head> ' ) with tag('title'): text('Report is generated') with tag('body'): with tag('div', id='title'): text( 'An Implementation of Face Detection Library to Teach Algorithm Basics in OpenCV and Python \nSummer 2017' ) with tag('div', id='logo'): doc.stag('img', src='RET_Title.png', klass="logo") ##run if the dlib library is selected... if (Alg == 1): #Alg.get()==1 imgdir = val[0] with tag('h1'): text('Your input image is the following') with tag('div', id='photo-container'): doc.stag('img', src='%s' % imgdir, klass="photo") # construct the shape predictor algorithm. print( 'DLIB Frontal face recognition algorithm is selected.' ) with tag('h2'): text( 'DLIB Frontal face recognition algorithm is selected.' ) args = ("-p shape_predictor_68_face_landmarks.dat") # initialize dlib's face detector (HOG-based) and then create # the facial landmark predictor detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor( "shape_predictor_68_face_landmarks.dat") # load the input image, resize it, and convert it to grayscale image = cv2.imread(imgdir) image = imutils.resize(image, width=500) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) doc._append("<br><hr>") print('....\tProcessing %s\t....\n' % imgdir) with tag('h4', id="center"): text('....\tProcessing %s\t....' % imgdir) #result='....\tProgram started processing %s\t....\n'%imgdir # detect faces in the grayscale image rects = detector(gray, 1) if (rects): print( 'Number of faces detected in the image: %d\n' % len(rects)) #result=result+'Number of faces detected in the image: %d\n' %(len(rects)) with tag('h3'): text( 'Number of faces detected in the image: %d' % len(rects)) # clone the original image so we can draw on it, then # draw rectangles on the image cloneRect = image.copy() # loop over the face detections fno = 0 for (i, rect) in enumerate(rects): # determine the facial landmarks for the face region, then # convert the landmark (x, y)-coordinates to a NumPy array shape = predictor(gray, rect) shape = face_utils.shape_to_np(shape) fno = fno + 1 print('STARTED processing FACE #%d' % fno) doc._append("<br><hr>") with tag('h2', id='faces'): text('STARTED processing FACE #%d' % fno) #result=result+'STARTED processing FACE #%d' %fno # loop over the face parts individually k = -1 for ( name, (i, j) ) in face_utils.FACIAL_LANDMARKS_IDXS.items(): k = k + 1 if (parts[k] == 1): # clone the original image so we can draw on it, then # display the name of the face part on the image clone = image.copy() cv2.putText( clone, str(fno) + "_" + name.upper() + ' Circled', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2) # loop over the subset of facial landmarks, drawing the # specific face part for (x, y) in shape[i:j]: cv2.circle(clone, (x, y), 1, (0, 255, 0), 2) # extract the ROI of the face region as a separate image (x, y, w, h) = cv2.boundingRect( np.array([shape[i:j]])) roi = image[y:y + h, x:x + w] roi = imutils.resize( roi, height=150, inter=cv2.INTER_CUBIC) # add text to resized ROI image cv2.putText( roi, str(fno) + "_" + name.upper(), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 1) # show the particular face part #cv2.imshow("cropped %s" %name, roi) if (cv2.imwrite( "allfaceparts/%d__cropped %s.jpg" % (fno, name), roi)): print( '\t%d_%s \tDetected, circled and saved.' % (fno, name.upper().ljust(15))) #result=result+'\t%d_%s \tDetected, circled and saved.\n' % (fno,name.upper().ljust(15)) with tag('div'): text( '%s Detected, circled and saved for Face #%d.' % (name.upper().ljust(15), fno)) with tag('div', id='photo-container'): doc.stag( 'img', src= 'allfaceparts/%d__cropped %s.jpg' % (fno, name), klass="faceparts-big") #cv2.imshow("Image %s" %name, clone) if (cv2.imwrite( "allfaceparts/%d_image %s.jpg" % (fno, name), clone)): print( '\t%d_%s \tCropped and saved.' % (fno, name.upper().ljust(15))) with tag('div'): text( '%s Cropped and saved for Face #%d.' % (name.upper().ljust(15), fno)) with tag('div', id='photo-container'): doc.stag( 'img', src= 'allfaceparts/%d_image %s.jpg' % (fno, name), klass="faceparts") #result=result+'\t%d_%s \tCropped and saved.\n' %(fno,name.upper().ljust(15)) #cv2.waitKey(0) else: print( 'Skipped analyzing %s on the face %d' % (name, fno)) with tag('div'): text( 'Skipped analyzing %s on the face %d' % (name, fno)) # convert dlib's rectangle to a OpenCV-style bounding box # [i.e., (x, y, w, h)], (x, y, w, h) = face_utils.rect_to_bb(rect) #crop the detected face and save it crop_img = cloneRect[y:y + h, x:x + w] #Resize the cropped image crop_img = imutils.resize( crop_img, height=450, inter=cv2.INTER_CUBIC) # add text to resized ROI image cv2.putText(crop_img, "FACE_#" + str(fno), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 1) if (cv2.imwrite( 'allfaceparts/Face_%d.jpg' % fno, crop_img)): print('Face #%d is cropped and saved.' % fno) with tag('div'): text('Face #%d is cropped and saved.' % fno) with tag('div', id='photo-container'): doc.stag( 'img', src='allfaceparts/Face_%d.jpg' % fno, klass="fullface") #result=result+'Face #%d is cropped and saved.' %fno cv2.rectangle(cloneRect, (x, y), (x + w, y + h), (0, 255, 0), 2) # show the face number cv2.putText(cloneRect, "Face #%d" % fno, (x - 10, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1) # loop over the (x, y)-coordinates for the facial landmarks # and draw them on the image for (x, y) in shape: cv2.circle(cloneRect, (x, y), 1, (0, 0, 255), -1) #cv2.imwrite("allfaceparts/%d_Complete face.jpg" %fno,cloneRect) print('COMPLETED processing FACE #%d.\n' % fno) with tag('h3', id='faces'): text('COMPLETED processing FACE #%d' % fno) #result=result+'COMPLETED processing FACE #%d.\n' %fno #cv2.waitKey(0) cv2.imwrite("allfaceparts/Faces_Complete.jpg", cloneRect) print( 'All detected faces are shown on complete image.' ) #result=result+'All detected faces are shown on complete image.' doc._append("<br><hr>") with tag('h3'): text( 'All detected faces are shown on complete image.' ) with tag('div', id='photo-container'): doc.stag('img', src='allfaceparts/Faces_Complete.jpg', klass="fullface") doc._append("<br><hr>") else: print( 'We found No faces in the image to analyze all face parts.' ) #result=result+'We found No faces in the image to analyze all face parts.' doc._append("<br><hr>") with tag('h4'): text( 'We found No faces in the image to analyze all face parts.' ) print( '\n....\tProgram completed processing %s"\t....' % imgdir) with tag('div'): text('....\tProgram completed processing image') doc._append("<br><hr>") #result=result+'\n....\tProgram completed processing "sample.jpg"\t....' #FaceText=Label(root, text=result, font=("Helvetica",6)) #FaceText.pack(side=LEFT) ##end if ##run if the dlib library is selected... elif (Alg.get() == 2): ''' print ('Haarcascade algorithm is selected.') with tag('h4'): text('Haarcascade algorithm is selected.') def draw_rects(img, rects, color): for x1, y1, x2, y2 in rects: cv2.rectangle(img, (x1, y1), (x2, y2), color, 2) def detect(img, cascade): rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30),flags=cv2.CASCADE_SCALE_IMAGE) if len(rects) == 0: return [] rects[:,2:] += rects[:,:2] return rects cascade_fn = args.get('--cascade', "haarcascades/haarcascade_frontalface_alt.xml") nested_fn = args.get('--nested-cascade', "haarcascades/haarcascade_eye.xml") cascade = cv2.CascadeClassifier(cascade_fn) nested = cv2.CascadeClassifier(nested_fn) ''' else: tkMessageBox.showinfo( "Please Correct", "Please choose an algorithm to continue") with tag('h4'): text( 'Please choose a valid file to generate report' ) result = doc.getvalue() time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') report = open("Report_%s.html" % time, "w+") report.write(result) report.close() def callback(event): webbrowser.open_new(r"Report_%s.html" % time) done = Label(root, text="STEP 4: Click to open the Report_%s file " % time, font=("Helvetica", 12), pady=10, bg="pink", fg="blue", cursor="hand2") done.pack(fill=X) done.bind("<Button-1>", callback) tkMessageBox.showinfo("Done", "Done your report file is saved.")
def _write_test_results_html_file(self, output_file, test_results): """ test_results = { test00: { 'cluster_probability_plot': 'input.png', 'most_probable_cluster_count': 1, 'results': { 1: { 'probability': 0.12, 'file': 'xyz.html' }, ... } ... } } :param output_file: :param test_results: :return: """ doc, tag, text = Doc().tagtext() with tag('html'): with tag('head'): with tag('style', type="text/css"): text(""" button { width: 150px; height: 50px; } .wbutton { width: 450px; } """) with tag('script', src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"): pass with tag('script'): text('data={};'.format(json.dumps(test_results))) doc._append(""" $(function(){ var selected_test = null; // Select all test cases var tests = Object.keys(data); tests.sort(); function select_result(title, cluster_count) { $('.current_view_title').text(title); $('.current_view_content').attr('src', selected_test['results'][cluster_count]['file']); } function select_test(test) { selected_test = data[test]; $('.test_button').css('background-color', ''); selected_test['button'].css('background-color', '#BBBBBB'); var target = $('.cluster_count_buttons') target.empty(); target.append('<h2>Cluster probabilities</h2>'); target.append('<img src="' + selected_test['cluster_probability_plot'] + '" width="450px" />'); var cluster_counts = Object.keys(selected_test['results']) cluster_counts.sort(function(a, b) { return a - b; }); var mpcc = selected_test['most_probable_cluster_count']; function add_btn(text, cluster_count) { var btn = $('<button class="wbutton" type="button">' + text + '</button>'); btn.click(function(){select_result(text, cluster_count);}); target.append(btn); return btn; } mpcc_btn = add_btn("Prediction (cluster count = " + mpcc + ")", mpcc); cluster_counts.map(function(cluster_count) { add_btn('Cluster count = ' + cluster_count + ", p = " + selected_test['results'][cluster_count]['probability'], cluster_count); }); mpcc_btn.click(); } // Create some buttons tests.map(function(test){ var btn = $('<button class="test_button" type="button" id="' + test +'">' + test + '</button>'); data[test]['button'] = btn; btn.click(function(){select_test(test);}); $('.test_buttons').append(btn); }); select_test(tests[0]); }); """) with tag('body'): with tag('h1'): text('Test collection') with tag('div', width="100%", style="background-color:#999999"): with tag('table'): with tag('tr', klass='test_buttons'): pass with tag('table', width="100%", height="80%"): with tag('tr'): with tag('td', style="vertical-align: top;", width="500px"): with tag('div', klass='cluster_count_buttons'): pass with tag('td', style="vertical-align: top;"): with tag('h2', klass="current_view_title"): pass with tag('iframe', klass="current_view_content", frameborder="0px", width="100%", height="100%"): pass html = doc.getvalue() # Save the html file with open(output_file, "w") as fh: fh.write(html) fh.flush() # It should be useless, but sometimes we had problems...
def gen_proj_page(data): user_info = load_user_info() PERSONAL_TEMPLATE = ''' <!DOCTYPE html> <html> <meta charset="UTF-8"> <head> <title>KNC -- {projname}</title> <link rel="stylesheet" href="../../style.css"> </head> <body style="padding-left: 20%;padding-right: 20%"> <a href="../../index.html">KNC Home</a> {everything_else} </body> </html> ''' doc, tag, text = Doc().tagtext() with tag('center'): with tag('h1'): text(data['projname']) doc._append("<br/>") with tag('center'): with tag('ul', id="nav", style="list-style-type: none; margin: 0; padding: 0"): for link in data['links']: with tag('a', href=data['links'][link]): with tag('li'): text(link) doc._append("<br/>") with tag('center'): with tag('h2'): with tag('b'): text('Contributors: ') u_idx = 0 for user in data['contributors']: if user[0] == '@': with tag('a', href='../../' + user): text(user_info[user]['name']) else: text(user) u_idx += 1 if u_idx < len(data['contributors']): text(', ') doc._append("<br/>") text(data['long_desc']) doc._append("<br/>\n\n") if 'images' in data: for img in data['images']: doc._append('<img src="%s" style="width: 25vw;">\n' % img) doc._append("<br/>\n\n") return PERSONAL_TEMPLATE.format( projname=data['projname'], everything_else=doc.getvalue(), )
def gen_personal_html(data): PERSONAL_TEMPLATE = ''' <!DOCTYPE html> <html> <meta charset="UTF-8"> <head> <title>KNC -- {knc_id}</title> <link rel="stylesheet" href="../style.css"> {header_stuff} </head> <body style="padding-left: 20%;padding-right: 20%"> <a href="../index.html">KNC Home</a> {everything_else} </body> </html> ''' doc, tag, text = Doc().tagtext() # if they want a webpage redirect if ('redirect_page_to_website' in data and 'website' in data and data['redirect_page_to_website']): # do the redirect redirect_header = ( '<meta http-equiv="refresh" content="0; URL=%s" />' % data['website']) # print a link also with tag('p'): text('redirecting to:') doc._append("<br/>") with tag('a', href=data['website']): text(data['website']) return PERSONAL_TEMPLATE.format( knc_id=data['knc_id'], everything_else=doc.getvalue(), header_stuff=redirect_header, ) with tag('center'): with tag('h1'): text(data['name']) with tag('h2'): with tag('a', href='mailto:' + data['email']): text(data['email']) with tag('h2'): text(data['role']) if 'bio' in data: with tag('p'): text(data['bio']) links_list = ['github', 'website', 'CV'] if any((x in data) for x in links_list): with tag('h2'): text('Links:') with tag('ul'): for x in links_list: if x in data: with tag('li'): with tag('a', href=data[x]): text(x) if 'interests' in data: with tag('h2'): text('Interests:') with tag('p'): text(data['interests']) if 'proj_blurb' in data: with tag('h2'): text('Projects:') with tag('p'): text(data['proj_blurb']) return PERSONAL_TEMPLATE.format( knc_id=data['knc_id'], everything_else=doc.getvalue(), header_stuff='', )
# coding: UTF-8 from yattag import Doc doc, tag, text, line = Doc(defaults={ 'title': 'Untitled', 'contact_message': 'You just won the lottery!' }, errors={ 'contact_message': 'Your message looks like spam.' }).ttl() line('h1', 'Contact form') with tag('form', action=""): doc.input(name='title', type='text') doc._append('\n') with doc.textarea(name='contact_message'): pass doc.stag('input', type='submit', value='Send my message') doc._append('\n') print(doc.getvalue()) s = doc.getvalue() f = open('text.txt', 'w') f.write(s) f.close()