Alibrown commited on
Commit
6fb7620
·
verified ·
1 Parent(s): 6a3bfec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -29
app.py CHANGED
@@ -44,23 +44,15 @@ def main():
44
  ['webp', 'jpg', 'png']
45
  )
46
 
47
- # Status-Flag für Optimierung
48
- if 'optimization_done' not in st.session_state:
49
- st.session_state.optimization_done = False
50
 
51
- if st.button("Bild optimieren", disabled=st.session_state.optimization_done):
52
- # Setze Flag, um mehrfache Optimierung zu verhindern
53
- st.session_state.optimization_done = True
54
-
55
- # Fortschrittsbalken
56
- progress_bar = st.progress(0)
57
- status_text = st.empty()
58
-
59
  try:
60
- # Simuliere Optimierungsprozess
61
- status_text.text("Optimierung startet...")
62
  progress_bar.progress(20)
63
- time.sleep(1)
64
 
65
  optimized_image = compress_image(
66
  original_image,
@@ -68,25 +60,20 @@ def main():
68
  quality=compression_quality
69
  )
70
 
71
- status_text.text("Bildverarbeitung...")
72
- progress_bar.progress(50)
73
- time.sleep(1)
74
 
75
  if optimized_image:
76
  img_byte_arr = io.BytesIO()
77
  optimized_image.save(img_byte_arr, format=target_format.upper(), quality=compression_quality)
78
  img_byte_arr.seek(0)
79
 
80
- status_text.text("Finalisiere...")
81
- progress_bar.progress(80)
82
- time.sleep(1)
83
 
84
  optimized_size_bytes = img_byte_arr.getbuffer().nbytes
85
  compression_ratio = (1 - optimized_size_bytes / original_size_bytes) * 100
86
 
87
- progress_bar.progress(100)
88
- status_text.text("Optimierung abgeschlossen!")
89
-
90
  st.subheader("Optimierungsergebnisse")
91
  col1, col2 = st.columns(2)
92
 
@@ -105,15 +92,11 @@ def main():
105
  mime=f"image/{target_format}"
106
  )
107
 
 
 
108
  except Exception as e:
109
  st.error(f"Fehler bei Bildoptimierung: {e}")
110
- # Setze Flag zurück bei Fehler
111
- st.session_state.optimization_done = False
112
-
113
- finally:
114
- # Lösche Fortschrittsbalken und Statustext
115
  progress_bar.empty()
116
- status_text.empty()
117
 
118
  except Exception as e:
119
  st.error(f"Fehler beim Laden des Bildes: {e}")
 
44
  ['webp', 'jpg', 'png']
45
  )
46
 
47
+ # Warnung vor mehrfachem Klicken
48
+ st.warning("⚠️ Bitte klicken Sie NUR EINMAL auf 'Bild optimieren'!")
 
49
 
50
+ progress_bar = st.progress(0)
51
+
52
+ if st.button("Bild optimieren"):
 
 
 
 
 
53
  try:
 
 
54
  progress_bar.progress(20)
55
+ time.sleep(0.5)
56
 
57
  optimized_image = compress_image(
58
  original_image,
 
60
  quality=compression_quality
61
  )
62
 
63
+ progress_bar.progress(60)
64
+ time.sleep(0.5)
 
65
 
66
  if optimized_image:
67
  img_byte_arr = io.BytesIO()
68
  optimized_image.save(img_byte_arr, format=target_format.upper(), quality=compression_quality)
69
  img_byte_arr.seek(0)
70
 
71
+ progress_bar.progress(100)
72
+ time.sleep(0.5)
 
73
 
74
  optimized_size_bytes = img_byte_arr.getbuffer().nbytes
75
  compression_ratio = (1 - optimized_size_bytes / original_size_bytes) * 100
76
 
 
 
 
77
  st.subheader("Optimierungsergebnisse")
78
  col1, col2 = st.columns(2)
79
 
 
92
  mime=f"image/{target_format}"
93
  )
94
 
95
+ progress_bar.empty()
96
+
97
  except Exception as e:
98
  st.error(f"Fehler bei Bildoptimierung: {e}")
 
 
 
 
 
99
  progress_bar.empty()
 
100
 
101
  except Exception as e:
102
  st.error(f"Fehler beim Laden des Bildes: {e}")