awacke1 commited on
Commit
7a57cb1
·
1 Parent(s): a69db2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -65,17 +65,24 @@ def get_download_link(file):
65
  b64 = base64.b64encode(bytes).decode()
66
  href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>download the latest revision</a>'
67
  return href
68
-
69
- def generate_hash_key(path):
70
- """Generate a unique hash key for a given file path."""
71
- return hashlib.md5(path.encode()).hexdigest()
72
 
73
  def show_file_operations(file_path):
74
- # Unique hash keys for each file and operation based on their path
75
- edit_button_key = f"edit_button_{generate_hash_key(file_path)}"
76
- save_button_key = f"save_button_{generate_hash_key(file_path)}"
77
- delete_button_key = f"delete_button_{generate_hash_key(file_path)}"
78
- content_key = f"content_{generate_hash_key(file_path)}"
 
 
 
 
 
 
 
 
79
 
80
  # Start Edit operation
81
  if st.button(f"✏️ Edit {os.path.basename(file_path)}", key=edit_button_key):
 
65
  b64 = base64.b64encode(bytes).decode()
66
  href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>download the latest revision</a>'
67
  return href
68
+ def generate_hash_key(path, counter):
69
+ """Generate a unique hash key for a given file path and counter."""
70
+ return hashlib.md5(f"{path}_{counter}".encode()).hexdigest()
 
71
 
72
  def show_file_operations(file_path):
73
+ # Increment counter for each file path
74
+ counter_key = f"counter_{file_path}"
75
+ if counter_key in st.session_state:
76
+ st.session_state[counter_key] += 1
77
+ else:
78
+ st.session_state[counter_key] = 1
79
+
80
+ # Unique hash keys for each file and operation based on their path and counter
81
+ counter = st.session_state[counter_key]
82
+ edit_button_key = f"edit_button_{generate_hash_key(file_path, counter)}"
83
+ save_button_key = f"save_button_{generate_hash_key(file_path, counter)}"
84
+ delete_button_key = f"delete_button_{generate_hash_key(file_path, counter)}"
85
+ content_key = f"content_{generate_hash_key(file_path, counter)}"
86
 
87
  # Start Edit operation
88
  if st.button(f"✏️ Edit {os.path.basename(file_path)}", key=edit_button_key):