awacke1 commited on
Commit
aef2e78
1 Parent(s): ba0df96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -30
app.py CHANGED
@@ -12,31 +12,22 @@ from camera_input_live import camera_input_live
12
  # Set wide layout
13
  st.set_page_config(layout="wide")
14
 
 
 
 
 
 
15
  # Function Definitions for Camera Feature
16
- def save_image(image):
17
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
18
- filename = f"captured_image_{timestamp}.png"
 
19
  bytes_data = image.getvalue()
20
  cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
21
  cv2.imwrite(filename, cv2_img)
22
  return filename
23
 
24
- def get_image_base64(image_path):
25
- with open(image_path, "rb") as image_file:
26
- return base64.b64encode(image_file.read()).decode()
27
-
28
- # Function Definitions for Chord Sheet Feature
29
- def process_line(line):
30
- if re.search(r'\b[A-G][#b]?m?\b', line):
31
- line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
32
- return line
33
-
34
- def process_chord_sheet(chord_sheet):
35
- processed_lines = []
36
- for line in chord_sheet.split('\n'):
37
- processed_line = process_line(line)
38
- processed_lines.append(processed_line)
39
- return '<br>'.join(processed_lines)
40
 
41
  # Main Function
42
  def main():
@@ -61,7 +52,8 @@ def main():
61
  image_placeholder.image(image)
62
 
63
  if time.time() - st.session_state['last_captured'] > snapshot_interval:
64
- filename = save_image(image)
 
65
  st.session_state['captured_images'].append(filename)
66
  st.session_state['last_captured'] = time.time()
67
 
@@ -73,20 +65,16 @@ def main():
73
  st.sidebar.markdown("## Captured Images")
74
  st.sidebar.markdown(sidebar_html, unsafe_allow_html=True)
75
 
 
 
 
76
  # Chord Sheet Section
77
  with col2:
78
- st.title("Chord Sheet Manager")
79
-
80
- all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
81
- selected_file = st.selectbox("Choose a Song:", all_files)
82
-
83
- if selected_file:
84
- with open(selected_file, 'r', encoding='utf-8') as file:
85
- chord_sheet = file.read()
86
- st.markdown(process_chord_sheet(chord_sheet), unsafe_allow_html=True)
87
 
88
- # Trigger a rerun to update the live feed
89
- #st.experimental_rerun()
 
90
 
91
  if __name__ == "__main__":
92
  main()
 
12
  # Set wide layout
13
  st.set_page_config(layout="wide")
14
 
15
+ # Decorator for caching images
16
+ @st.cache(allow_output_mutation=True)
17
+ def get_image_count():
18
+ return {'count': 0}
19
+
20
  # Function Definitions for Camera Feature
21
+ def save_image(image, image_count):
22
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
23
+ filename = f"captured_image_{timestamp}_{image_count['count']}.png"
24
+ image_count['count'] += 1
25
  bytes_data = image.getvalue()
26
  cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
27
  cv2.imwrite(filename, cv2_img)
28
  return filename
29
 
30
+ # Other function definitions...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # Main Function
33
  def main():
 
52
  image_placeholder.image(image)
53
 
54
  if time.time() - st.session_state['last_captured'] > snapshot_interval:
55
+ image_count = get_image_count()
56
+ filename = save_image(image, image_count)
57
  st.session_state['captured_images'].append(filename)
58
  st.session_state['last_captured'] = time.time()
59
 
 
65
  st.sidebar.markdown("## Captured Images")
66
  st.sidebar.markdown(sidebar_html, unsafe_allow_html=True)
67
 
68
+ # JavaScript Timer
69
+ st.markdown(f"<script>setInterval(function() {{ document.getElementById('timer').innerHTML = new Date().toLocaleTimeString(); }}, 1000);</script><div>Current Time: <span id='timer'></span></div>", unsafe_allow_html=True)
70
+
71
  # Chord Sheet Section
72
  with col2:
73
+ # ... (Chord Sheet section remains unchanged) ...
 
 
 
 
 
 
 
 
74
 
75
+ # Trigger a rerun only when the snapshot interval is reached
76
+ if 'last_captured' in st.session_state and time.time() - st.session_state['last_captured'] > snapshot_interval:
77
+ st.experimental_rerun()
78
 
79
  if __name__ == "__main__":
80
  main()