ssh-AI commited on
Commit
4e9d611
·
verified ·
1 Parent(s): d05a7d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  from PIL import Image, ImageEnhance
3
  from io import BytesIO
4
- import numpy as np
5
  import zipfile
6
  import os
7
  from fpdf import FPDF
@@ -52,7 +51,6 @@ if uploaded_files:
52
  st.markdown(f"---\n### 🖼️ {file.name}")
53
  original = Image.open(BytesIO(file_bytes)).convert("RGB")
54
 
55
- # Init state
56
  if f"original_{key}" not in st.session_state:
57
  st.session_state[f"original_{key}"] = original
58
  st.session_state[f"angle_{key}"] = 0
@@ -113,8 +111,10 @@ if uploaded_files:
113
 
114
  # --- EXPORT SECTION ---
115
  st.markdown("### 🧾 Export Options")
116
- col1, col2 = st.columns([1, 1])
117
- with col1:
 
 
118
  if st.button("📦 Generate ZIP"):
119
  zip_buffer = BytesIO()
120
  with zipfile.ZipFile(zip_buffer, "w") as zipf:
@@ -123,9 +123,14 @@ if uploaded_files:
123
  img.save(buffer, format="PNG")
124
  zipf.writestr(f"{name}.png", buffer.getvalue())
125
  zip_buffer.seek(0)
126
- st.download_button("⬇️ Download ZIP", zip_buffer, "images.zip", mime="application/zip", key="zip_dl")
127
-
128
- with col2:
 
 
 
 
 
129
  if st.button("📄 Generate PDF"):
130
  pdf = FPDF()
131
  tmp_paths = []
@@ -138,6 +143,9 @@ if uploaded_files:
138
  out_path = "/tmp/final.pdf"
139
  pdf.output(out_path)
140
  with open(out_path, "rb") as f:
141
- st.download_button("⬇️ Download PDF", f, "scanned.pdf", mime="application/pdf", key="pdf_dl")
142
  for p in tmp_paths + [out_path]:
143
  os.remove(p)
 
 
 
 
1
  import streamlit as st
2
  from PIL import Image, ImageEnhance
3
  from io import BytesIO
 
4
  import zipfile
5
  import os
6
  from fpdf import FPDF
 
51
  st.markdown(f"---\n### 🖼️ {file.name}")
52
  original = Image.open(BytesIO(file_bytes)).convert("RGB")
53
 
 
54
  if f"original_{key}" not in st.session_state:
55
  st.session_state[f"original_{key}"] = original
56
  st.session_state[f"angle_{key}"] = 0
 
111
 
112
  # --- EXPORT SECTION ---
113
  st.markdown("### 🧾 Export Options")
114
+
115
+ # ZIP inline layout
116
+ zip_col1, zip_col2 = st.columns([1, 2])
117
+ with zip_col1:
118
  if st.button("📦 Generate ZIP"):
119
  zip_buffer = BytesIO()
120
  with zipfile.ZipFile(zip_buffer, "w") as zipf:
 
123
  img.save(buffer, format="PNG")
124
  zipf.writestr(f"{name}.png", buffer.getvalue())
125
  zip_buffer.seek(0)
126
+ st.session_state["zip_file"] = zip_buffer
127
+ with zip_col2:
128
+ if "zip_file" in st.session_state:
129
+ st.download_button("⬇️ Download ZIP", st.session_state["zip_file"], "images.zip", mime="application/zip", key="zip_dl")
130
+
131
+ # PDF inline layout
132
+ pdf_col1, pdf_col2 = st.columns([1, 2])
133
+ with pdf_col1:
134
  if st.button("📄 Generate PDF"):
135
  pdf = FPDF()
136
  tmp_paths = []
 
143
  out_path = "/tmp/final.pdf"
144
  pdf.output(out_path)
145
  with open(out_path, "rb") as f:
146
+ st.session_state["pdf_file"] = f.read()
147
  for p in tmp_paths + [out_path]:
148
  os.remove(p)
149
+ with pdf_col2:
150
+ if "pdf_file" in st.session_state:
151
+ st.download_button("⬇️ Download PDF", st.session_state["pdf_file"], "scanned.pdf", mime="application/pdf", key="pdf_dl")