Spaces:
Build error
Build error
Upload app.py
Browse files7 unmodified lines89101112131415161717 unmodified lines353637383940414243444546474849505152535455565767 unmodified lines12512612712812913013115 unmodified lines1471481491501511521531541551561571581591601611627 unmodified linesimport requestsfrom io import BytesIOfrom openpyxl.styles import Border, Side,Alignmentdef convert_pdf_to_excel(pdf_file):rows = []firstcolumn=''# Function to extract text from a PDF and process it into a tabular format17 unmodified linessublists = []i = 3 # Index to track position in the listwhile i < len(rows):# Check if the current value is "Department Name"if rows[i] == 'Department Name':# Skip next 6 values (including the current one)department=rows[i+1]department=department.strip()section=rows[i+5]sem=rows[i+2]i += 7print(department)print(sem)print(section)else:# Extract a sublist of next 3 elementssublist = rows[i:i + 3]sublists.append(sublist)i += 3 # Move the index to the next set of 3 elements67 unmodified linesfile_content = get_file_content_as_bytes(file_path)st.download_button(label='Download Excel mac',data=file_content,file_name=file_path,mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'15 unmodified lineswith open(file_path, "wb") as f:f.write(uploaded_file.getbuffer())st.success(f'File "{file_name}" saved ')excel_file = convert_pdf_to_excel(file_name)with open('./demo.css') as f:css = f.read()st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)7 unmodified lines891011121314151617181917 unmodified lines37383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868767 unmodified lines15515615715815916016115 unmodified lines1771781791801811821831841851861871887 unmodified linesimport requestsfrom io import BytesIOfrom openpyxl.styles import Border, Side,Alignmentdepartment='Default 'sem='Default 'section='Default'def convert_pdf_to_excel(pdf_file):rows = []firstcolumn=''# Function to extract text from a PDF and process it into a tabular format17 unmodified linessublists = []i = 3 # Index to track position in the listspace=Falsewhile i < len(rows):# Check if the current value is "Department Name"if rows[i] == 'Department Name':# print(rows[i])# print(rows[i+1])# print(rows[i+2])# print(rows[i+3])# print(rows[i+4])# print(rows[i+5])# print(rows[i+6])# print(rows[i+7])# print(rows[i+8])# print(rows[i+9])# break# Skip next 6 values (including the current one)print(rows[i])department=rows[i+1]department=department.strip()print("Dept is ",department)sem=rows[i+2]if(sem==' '):space=Truesem=rows[i+3]print("sem is ",sem)section=rows[i+5]if(section=='Semester'):section=rows[i+6]print("section is ",section)i += 7if(space==True):i=i+1# print(department)# print(sem)# print(section)else:# Extract a sublist of next 3 elementsprint('val',rows[i])sublist = rows[i:i + 3]sublists.append(sublist)i += 3 # Move the index to the next set of 3 elements67 unmodified linesfile_content = get_file_content_as_bytes(file_path)st.download_button(label='Download Excel File',data=file_content,file_name=file_path,mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'15 unmodified lineswith open(file_path, "wb") as f:f.write(uploaded_file.getbuffer())st.success(f'File "{file_name}" saved at "{file_path}"')excel_file = convert_pdf_to_excel(file_name)
app.py+42-16