awacke1 commited on
Commit
a1de66d
β€’
1 Parent(s): b8fdfd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -26
app.py CHANGED
@@ -1,32 +1,37 @@
1
- from bs4 import BeautifulSoup
2
- import requests
3
- from zipfile import ZipFile
4
- import os
5
 
6
- # URL of the webpage
7
- url = 'https://tabs.ultimate-guitar.com/tab/neko-case/hold-on-hold-on-chords-1237853'
 
 
 
 
 
8
 
9
- # Send a request to the URL
10
- response = requests.get(url)
11
- html_content = response.text
 
 
 
 
12
 
13
- # Parse HTML
14
- soup = BeautifulSoup(html_content, 'html.parser')
 
15
 
16
- # Find all image tags
17
- image_tags = soup.find_all('img') # Modify this line based on actual HTML structure
18
 
19
- # Directory to store images
20
- os.makedirs('chord_images', exist_ok=True)
 
 
 
 
 
 
21
 
22
- # Zip file to store images
23
- with ZipFile('chord_images.zip', 'w') as zipf:
24
- for i, img in enumerate(image_tags):
25
- img_url = img['src'] # Assuming 'src' contains the image URL
26
- img_data = requests.get(img_url).content
27
- img_filename = f'chord_images/image_{i}.jpg'
28
- with open(img_filename, 'wb') as f:
29
- f.write(img_data)
30
- zipf.write(img_filename)
31
-
32
- print("Images saved and zipped.")
 
1
+ import streamlit as st
2
+ import re
 
 
3
 
4
+ # Function to process each line of the chord sheet
5
+ def process_line(line):
6
+ # Check if the line is a chord line (contains chord symbols)
7
+ if re.search(r'\b[A-G][#b]?m?\b', line):
8
+ # Replace chord symbols with image tags
9
+ line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
10
+ return line
11
 
12
+ # Function to process the entire chord sheet
13
+ def process_chord_sheet(chord_sheet):
14
+ processed_lines = []
15
+ for line in chord_sheet.split('\n'):
16
+ processed_line = process_line(line)
17
+ processed_lines.append(processed_line)
18
+ return '<br>'.join(processed_lines)
19
 
20
+ # Streamlit app
21
+ def main():
22
+ st.title('Chord Sheet Processor')
23
 
24
+ # Text area for user to input the chord sheet
25
+ chord_sheet_input = st.text_area("Enter your chord sheet here:", height=300)
26
 
27
+ if st.button('Process Chord Sheet'):
28
+ if chord_sheet_input:
29
+ # Processing the chord sheet
30
+ processed_sheet = process_chord_sheet(chord_sheet_input)
31
+ # Displaying the processed chord sheet
32
+ st.markdown(processed_sheet, unsafe_allow_html=True)
33
+ else:
34
+ st.error("Please input a chord sheet to process.")
35
 
36
+ if __name__ == '__main__':
37
+ main()