Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import re
|
|
|
|
| 3 |
|
| 4 |
# Function to process each line of the chord sheet
|
| 5 |
def process_line(line):
|
|
@@ -17,13 +18,50 @@ def process_chord_sheet(chord_sheet):
|
|
| 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
|
|
@@ -33,5 +71,11 @@ def main():
|
|
| 33 |
else:
|
| 34 |
st.error("Please input a chord sheet to process.")
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
if __name__ == '__main__':
|
| 37 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import re
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
# Function to process each line of the chord sheet
|
| 6 |
def process_line(line):
|
|
|
|
| 18 |
processed_lines.append(processed_line)
|
| 19 |
return '<br>'.join(processed_lines)
|
| 20 |
|
| 21 |
+
# Functions to create search URLs
|
| 22 |
+
def create_search_url_wikipedia(artist_song):
|
| 23 |
+
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
|
| 24 |
+
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
|
| 25 |
+
|
| 26 |
+
def create_search_url_youtube(artist_song):
|
| 27 |
+
base_url = "https://www.youtube.com/results?search_query="
|
| 28 |
+
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
|
| 29 |
+
|
| 30 |
+
def create_search_url_chords(artist_song):
|
| 31 |
+
base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value="
|
| 32 |
+
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
|
| 33 |
+
|
| 34 |
+
def create_search_url_lyrics(artist_song):
|
| 35 |
+
base_url = "https://www.google.com/search?q="
|
| 36 |
+
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') + '+lyrics'
|
| 37 |
+
|
| 38 |
# Streamlit app
|
| 39 |
def main():
|
| 40 |
st.title('Chord Sheet Processor')
|
| 41 |
|
| 42 |
+
# Song name and artist input
|
| 43 |
+
song_name_artist = st.text_input("Song Name by Music Artist", value="Hold On, Hold On by Neko Case")
|
| 44 |
+
|
| 45 |
+
# File operations
|
| 46 |
+
filename = song_name_artist.replace(", ", "_").replace(" ", "_").lower() + ".txt"
|
| 47 |
+
if st.button('Open Chord Sheet'):
|
| 48 |
+
if os.path.exists(filename):
|
| 49 |
+
with open(filename, "r") as file:
|
| 50 |
+
chord_sheet = file.read()
|
| 51 |
+
st.text_area("Chord Sheet", chord_sheet, height=300)
|
| 52 |
+
processed_sheet = process_chord_sheet(chord_sheet)
|
| 53 |
+
st.markdown(processed_sheet, unsafe_allow_html=True)
|
| 54 |
+
else:
|
| 55 |
+
st.error("File not found.")
|
| 56 |
+
|
| 57 |
# Text area for user to input the chord sheet
|
| 58 |
chord_sheet_input = st.text_area("Enter your chord sheet here:", height=300)
|
| 59 |
|
| 60 |
+
if st.button('Save Chord Sheet'):
|
| 61 |
+
with open(filename, "w") as file:
|
| 62 |
+
file.write(chord_sheet_input)
|
| 63 |
+
st.success("Chord sheet saved.")
|
| 64 |
+
|
| 65 |
if st.button('Process Chord Sheet'):
|
| 66 |
if chord_sheet_input:
|
| 67 |
# Processing the chord sheet
|
|
|
|
| 71 |
else:
|
| 72 |
st.error("Please input a chord sheet to process.")
|
| 73 |
|
| 74 |
+
# Displaying links
|
| 75 |
+
st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_name_artist)})")
|
| 76 |
+
st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_name_artist)})")
|
| 77 |
+
st.markdown(f"[🎸Chords]({create_search_url_chords(song_name_artist)})")
|
| 78 |
+
st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_name_artist)})")
|
| 79 |
+
|
| 80 |
if __name__ == '__main__':
|
| 81 |
main()
|