def window():
    global lastFilename
    name,ext=os.path.splitext(request.args.get('type'))
    filenamenew=name+ext
    lastFilename=filenamenew
    status=1
    
    if ext==".pdf":
        # creating a pdf file object 
        pdfFileObj = open(UPLOAD_FOLDER+"/"+filenamenew, 'rb')    
        # creating a pdf reader object 
        pdfReader = PyPDF2.PdfFileReader(pdfFileObj)      
        # printing number of pages in pdf file 
        print(pdfReader.numPages) 
        #print(pdfReader.getDocumentInfo())
        #print(pdfReader.getIsEncrypted())                
        # creating a page object 
        bundle=""
        for i in range(1,pdfReader.numPages):
            pageObj = pdfReader.getPage(i)
            # extracting text from page 
            #print(pageObj.extractText())
            bundle+=pageObj.extractText()      
        #print(bundle)
        # closing the pdf file object 
        pdfFileObj.close()
        
        #Auto tagging
        t = AutoTagify()
        t.text = bundle
        #print(t.tag_list())
        e_words = list(dict.fromkeys(t.tag_list()))  
        #print(e_words)

    else:
        file = open(UPLOAD_FOLDER+"/"+filenamenew,"r+") 
        #print(type(file.read()))

        t = AutoTagify()
        t.text = file.read()
        #print(len(t.tag_list()))
        e_words = list(dict.fromkeys(t.tag_list()))  
        #print(e_words)
        file.close() 
    
    #Summarization
    summary=generate_summary(UPLOAD_FOLDER+"/"+filenamenew,5)

    conn = sqlite3.connect('TAGS.db')
    #c = conn.cursor()
    # Insert a row of data
    conn.execute('''INSERT INTO Tag (Filename,Auto_tag,Manual_tag,Summary,status) VALUES (?,?,?,?,?)''',(filenamenew, str(e_words),str([]),str(summary),status))
            
    # Save (commit) the changes
    conn.commit()
    conn.close()
        
    return render_template('window.html',F=filenamenew,L=e_words)