Mavhas commited on
Commit
85bed2a
·
verified ·
1 Parent(s): a8035d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -34,10 +34,11 @@ if password_entered == correct_password:
34
  for uploaded_file in uploaded_files:
35
  try:
36
  image = Image.open(uploaded_file)
37
- st.image(image, caption=uploaded_file.name, use_column_width=True)
38
 
39
  # Save image to static folder and update data.txt
40
- with open(os.path.join("static", uploaded_file.name), "wb") as f:
 
41
  f.write(uploaded_file.getvalue())
42
 
43
  saved_data["images"].append(uploaded_file.name)
@@ -46,11 +47,12 @@ if password_entered == correct_password:
46
 
47
  except Exception as e:
48
  st.error(f"Error opening image {uploaded_file.name}: {e}")
 
49
  elif saved_data["images"]: # Show previously uploaded images
50
  for image_name in saved_data["images"]:
51
  try:
52
- image_path = os.path.join("static", image_name)
53
- image = Image.open(image_path)
54
  st.image(image, caption=image_name, use_column_width=True)
55
  except FileNotFoundError:
56
  st.warning(f"Could not load previously saved image: {image_name}. It might have been deleted.")
@@ -66,7 +68,7 @@ if password_entered == correct_password:
66
  with open("data.txt", "w") as f:
67
  f.write(str(saved_data))
68
  st.success("Message saved!")
69
- st.rerun() # Corrected: st.rerun()
70
 
71
  if saved_data["messages"]: # Display previously saved messages
72
  for message in saved_data["messages"]:
@@ -75,7 +77,6 @@ if password_entered == correct_password:
75
  elif selected_tab == "Reasons":
76
  st.write("## Reasons I Love You")
77
 
78
- # Display existing reasons first
79
  if saved_data["reasons"]:
80
  for reason in saved_data["reasons"]:
81
  st.write(f"- {reason}")
@@ -87,7 +88,7 @@ if password_entered == correct_password:
87
  with open("data.txt", "w") as f:
88
  f.write(str(saved_data))
89
  st.success("Reason saved!")
90
- st.rerun() # Corrected: st.rerun()
91
 
92
  elif password_entered:
93
  st.error("Incorrect secret word. Try again.")
 
34
  for uploaded_file in uploaded_files:
35
  try:
36
  image = Image.open(uploaded_file)
37
+ st.image(image, caption=uploaded_file.name, use_container_width=True)
38
 
39
  # Save image to static folder and update data.txt
40
+ image_path = os.path.join("static", uploaded_file.name)
41
+ with open(image_path, "wb") as f:
42
  f.write(uploaded_file.getvalue())
43
 
44
  saved_data["images"].append(uploaded_file.name)
 
47
 
48
  except Exception as e:
49
  st.error(f"Error opening image {uploaded_file.name}: {e}")
50
+
51
  elif saved_data["images"]: # Show previously uploaded images
52
  for image_name in saved_data["images"]:
53
  try:
54
+ image_path = os.path.join("static", image_name) # Correct path!
55
+ image = Image.open(image_path) # Open from correct path
56
  st.image(image, caption=image_name, use_column_width=True)
57
  except FileNotFoundError:
58
  st.warning(f"Could not load previously saved image: {image_name}. It might have been deleted.")
 
68
  with open("data.txt", "w") as f:
69
  f.write(str(saved_data))
70
  st.success("Message saved!")
71
+ st.rerun()
72
 
73
  if saved_data["messages"]: # Display previously saved messages
74
  for message in saved_data["messages"]:
 
77
  elif selected_tab == "Reasons":
78
  st.write("## Reasons I Love You")
79
 
 
80
  if saved_data["reasons"]:
81
  for reason in saved_data["reasons"]:
82
  st.write(f"- {reason}")
 
88
  with open("data.txt", "w") as f:
89
  f.write(str(saved_data))
90
  st.success("Reason saved!")
91
+ st.rerun()
92
 
93
  elif password_entered:
94
  st.error("Incorrect secret word. Try again.")