engrharis commited on
Commit
9967e81
·
verified ·
1 Parent(s): b6c3e5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -14,7 +14,7 @@ def generate_pdf(images_with_sequence):
14
 
15
  images_with_sequence.sort(key=lambda x: x[1])
16
 
17
- config = pdfkit.configuration(wkhtmltopdf=r'/usr/bin/wkhtmltopdf') #provide your wkhtmltopdf path here
18
  pdf_options = {
19
  "margin-top": "0.5in",
20
  "margin-right": "0.5in",
@@ -32,27 +32,27 @@ def generate_pdf(images_with_sequence):
32
 
33
  st.title("Image to PDF Converter (Multiple Images)")
34
 
35
- uploaded_images = st.file_uploader("Upload Images", type=["jpg", "jpeg", "png"], accept_multiple=True)
36
 
37
  if uploaded_images:
38
  num_images = len(uploaded_images)
39
- if num_images > 0: #check if any image is uploaded
40
  images_with_sequence = []
41
 
42
  for i, image_file in enumerate(uploaded_images):
43
  st.image(image_file, width=250)
44
  sequence_options = [str(j) for j in range(1, num_images + 1)]
45
- default_index = i #set default selection of sequence as the order of upload
46
- sequence_number = st.selectbox(f"Sequence Number for Image {i+1}", sequence_options, index = default_index)
47
  processed_image, processed_sequence = process_image(image_file, int(sequence_number))
48
  images_with_sequence.append((processed_image, processed_sequence))
49
 
50
  if st.button("Generate PDF"):
51
  pdf_name = generate_pdf(images_with_sequence)
52
- if pdf_name: #check if pdf is generated successfully
53
  st.success(f"PDF generated! Download: {pdf_name}")
54
  with open(pdf_name, "rb") as pdf_file:
55
  st.download_button("Download PDF", pdf_file, file_name=pdf_name)
56
- os.remove(pdf_name) #remove the file after download
57
  else:
58
- st.write("Please upload images to continue")
 
14
 
15
  images_with_sequence.sort(key=lambda x: x[1])
16
 
17
+ config = pdfkit.configuration(wkhtmltopdf=r'/usr/bin/wkhtmltopdf') # provide your wkhtmltopdf path here
18
  pdf_options = {
19
  "margin-top": "0.5in",
20
  "margin-right": "0.5in",
 
32
 
33
  st.title("Image to PDF Converter (Multiple Images)")
34
 
35
+ uploaded_images = st.file_uploader("Upload Images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
36
 
37
  if uploaded_images:
38
  num_images = len(uploaded_images)
39
+ if num_images > 0: # check if any image is uploaded
40
  images_with_sequence = []
41
 
42
  for i, image_file in enumerate(uploaded_images):
43
  st.image(image_file, width=250)
44
  sequence_options = [str(j) for j in range(1, num_images + 1)]
45
+ default_index = i # set default selection of sequence as the order of upload
46
+ sequence_number = st.selectbox(f"Sequence Number for Image {i+1}", sequence_options, index=default_index)
47
  processed_image, processed_sequence = process_image(image_file, int(sequence_number))
48
  images_with_sequence.append((processed_image, processed_sequence))
49
 
50
  if st.button("Generate PDF"):
51
  pdf_name = generate_pdf(images_with_sequence)
52
+ if pdf_name: # check if pdf is generated successfully
53
  st.success(f"PDF generated! Download: {pdf_name}")
54
  with open(pdf_name, "rb") as pdf_file:
55
  st.download_button("Download PDF", pdf_file, file_name=pdf_name)
56
+ os.remove(pdf_name) # remove the file after download
57
  else:
58
+ st.write("Please upload images to continue")