ssh-AI commited on
Commit
61c4b5e
·
verified ·
1 Parent(s): 9f046e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -25
app.py CHANGED
@@ -7,44 +7,44 @@ import zipfile
7
  from fpdf import FPDF
8
  from streamlit_cropper import st_cropper
9
 
10
- # --- CONFIG ---
11
  st.set_page_config(page_title="Smart Doc Scanner", page_icon="🖼️", layout="centered")
12
 
13
- # --- BACKGROUND STYLE ---
14
  def set_background():
15
- page_bg_img = f"""
16
  <style>
17
- [data-testid="stAppViewContainer"] {{
18
- background-image: url("https://images.unsplash.com/photo-1524995997946-a1c2e315a42f");
19
  background-size: cover;
20
- }}
21
- [data-testid="stHeader"] {{
22
- background: rgba(0, 0, 0, 0);
23
- }}
 
 
 
 
 
 
 
 
 
 
24
  </style>
25
  """
26
  st.markdown(page_bg_img, unsafe_allow_html=True)
27
 
28
  set_background()
29
 
30
- # --- LIGHT/DARK MODE TOGGLE ---
31
- mode = st.selectbox("Select Theme:", ["Light Mode", "Dark Mode"])
32
- if mode == "Dark Mode":
33
- dark_style = """
34
- <style>
35
- body { background-color: #222; color: white; }
36
- </style>
37
- """
38
- st.markdown(dark_style, unsafe_allow_html=True)
39
-
40
- # --- APP TITLE ---
41
  st.markdown("<h1 style='text-align: center; color: #2E86C1;'>📄 Smart ID & Document Scanner</h1>", unsafe_allow_html=True)
42
  st.write("---")
43
 
44
  # --- MODE SELECTION ---
45
  app_mode = st.radio("Select Mode:", ["Normal Mode (No Editing)", "Advanced Mode (Edit Each Image)"])
46
 
47
- # --- UPLOAD IMAGES ---
48
  uploaded_files = st.file_uploader("Upload your Images", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
49
 
50
  if uploaded_files:
@@ -67,19 +67,26 @@ if uploaded_files:
67
  st.subheader(f"Editing: {uploaded_file.name}")
68
 
69
  # Cropper
70
- cropped_img = st_cropper(
71
  st.session_state[f"edited_{idx}"],
72
  realtime_update=True,
73
  box_color='#FF9900',
74
  aspect_ratio=None
75
  )
76
 
 
 
 
 
 
 
 
77
  # Actions
78
  col1, col2, col3, col4 = st.columns(4)
79
 
80
  with col1:
81
  if st.button(f"Enhance {idx}", key=f"enhance_{idx}"):
82
- enhancer = ImageEnhance.Contrast(cropped_img)
83
  enhanced_img = enhancer.enhance(1.5)
84
  sharpener = ImageEnhance.Sharpness(enhanced_img)
85
  st.session_state[f"edited_{idx}"] = sharpener.enhance(2.0)
@@ -87,7 +94,7 @@ if uploaded_files:
87
  with col2:
88
  angle = st.slider(f"Rotate {uploaded_file.name}", -180, 180, 0, key=f"rotate_{idx}")
89
  if angle != 0:
90
- st.session_state[f"edited_{idx}"] = cropped_img.rotate(angle, expand=True)
91
 
92
  with col3:
93
  if st.button(f"Reset {idx}", key=f"reset_{idx}"):
@@ -97,7 +104,7 @@ if uploaded_files:
97
  with col4:
98
  st.write("")
99
 
100
- # Show Image
101
  st.image(st.session_state[f"edited_{idx}"], caption=f"Edited {uploaded_file.name}", use_container_width=True)
102
  processed_images.append(st.session_state[f"edited_{idx}"])
103
 
 
7
  from fpdf import FPDF
8
  from streamlit_cropper import st_cropper
9
 
10
+ # --- PAGE CONFIG ---
11
  st.set_page_config(page_title="Smart Doc Scanner", page_icon="🖼️", layout="centered")
12
 
13
+ # --- BACKGROUND with OVERLAY ---
14
  def set_background():
15
+ page_bg_img = """
16
  <style>
17
+ [data-testid="stAppViewContainer"] {
18
+ background-image: url('https://images.unsplash.com/photo-1524995997946-a1c2e315a42f');
19
  background-size: cover;
20
+ background-position: center;
21
+ }
22
+ [data-testid="stAppViewContainer"]::before {
23
+ content: "";
24
+ position: absolute;
25
+ top: 0; left: 0;
26
+ width: 100%; height: 100%;
27
+ background: rgba(255, 255, 255, 0.7); /* White transparent overlay */
28
+ z-index: 0;
29
+ }
30
+ .stApp {
31
+ position: relative;
32
+ z-index: 1;
33
+ }
34
  </style>
35
  """
36
  st.markdown(page_bg_img, unsafe_allow_html=True)
37
 
38
  set_background()
39
 
40
+ # --- TITLE ---
 
 
 
 
 
 
 
 
 
 
41
  st.markdown("<h1 style='text-align: center; color: #2E86C1;'>📄 Smart ID & Document Scanner</h1>", unsafe_allow_html=True)
42
  st.write("---")
43
 
44
  # --- MODE SELECTION ---
45
  app_mode = st.radio("Select Mode:", ["Normal Mode (No Editing)", "Advanced Mode (Edit Each Image)"])
46
 
47
+ # --- FILE UPLOAD ---
48
  uploaded_files = st.file_uploader("Upload your Images", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
49
 
50
  if uploaded_files:
 
67
  st.subheader(f"Editing: {uploaded_file.name}")
68
 
69
  # Cropper
70
+ crop_output = st_cropper(
71
  st.session_state[f"edited_{idx}"],
72
  realtime_update=True,
73
  box_color='#FF9900',
74
  aspect_ratio=None
75
  )
76
 
77
+ # If output is numpy array, convert to PIL Image
78
+ if isinstance(crop_output, np.ndarray):
79
+ crop_output = Image.fromarray(crop_output)
80
+
81
+ # Save cropped image
82
+ st.session_state[f"edited_{idx}"] = crop_output
83
+
84
  # Actions
85
  col1, col2, col3, col4 = st.columns(4)
86
 
87
  with col1:
88
  if st.button(f"Enhance {idx}", key=f"enhance_{idx}"):
89
+ enhancer = ImageEnhance.Contrast(st.session_state[f"edited_{idx}"])
90
  enhanced_img = enhancer.enhance(1.5)
91
  sharpener = ImageEnhance.Sharpness(enhanced_img)
92
  st.session_state[f"edited_{idx}"] = sharpener.enhance(2.0)
 
94
  with col2:
95
  angle = st.slider(f"Rotate {uploaded_file.name}", -180, 180, 0, key=f"rotate_{idx}")
96
  if angle != 0:
97
+ st.session_state[f"edited_{idx}"] = st.session_state[f"edited_{idx}"].rotate(angle, expand=True)
98
 
99
  with col3:
100
  if st.button(f"Reset {idx}", key=f"reset_{idx}"):
 
104
  with col4:
105
  st.write("")
106
 
107
+ # Show Edited Image
108
  st.image(st.session_state[f"edited_{idx}"], caption=f"Edited {uploaded_file.name}", use_container_width=True)
109
  processed_images.append(st.session_state[f"edited_{idx}"])
110