Spaces:
Sleeping
Sleeping
yabramuvdi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import HfApiEngine
|
3 |
-
from transformers.agents import ReactCodeAgent, ReactJsonAgent,
|
4 |
from transformers.agents.search import DuckDuckGoSearchTool, VisitWebpageTool
|
5 |
from huggingface_hub import login
|
6 |
|
@@ -62,33 +62,17 @@ def initialize_agents():
|
|
62 |
# Streamlit App
|
63 |
def main():
|
64 |
st.title("Lyrics Finder App 🎵")
|
65 |
-
st.write("Enter the name of the song and optionally the artist to retrieve the lyrics
|
66 |
|
67 |
authenticate_hf()
|
68 |
manager_agent = initialize_agents()
|
69 |
|
70 |
-
#
|
71 |
-
|
72 |
-
"Search for Pelo Suelto by Elsa y Elmar",
|
73 |
-
"Get the lyrics for Hips Don't Lie",
|
74 |
-
]
|
75 |
-
|
76 |
-
# Suggest examples as clickable buttons
|
77 |
-
st.markdown("### Example Queries")
|
78 |
-
example_task = None
|
79 |
-
for example in examples:
|
80 |
-
if st.button(example):
|
81 |
-
example_task = example
|
82 |
-
|
83 |
-
# Custom input for user queries
|
84 |
-
custom_query = st.text_input("Or enter your own song and artist (e.g., 'Shape of You by Ed Sheeran')", "")
|
85 |
-
|
86 |
-
# Determine the task
|
87 |
-
task = example_task if example_task else custom_query
|
88 |
|
89 |
if st.button("Find Lyrics"):
|
90 |
-
if
|
91 |
-
st.error("Please
|
92 |
else:
|
93 |
st.write("Processing your request, please wait...")
|
94 |
with st.spinner("Agents are working hard to find the lyrics..."):
|
@@ -101,7 +85,7 @@ def main():
|
|
101 |
|
102 |
while not done and attempts < max_attempts:
|
103 |
try:
|
104 |
-
result = manager_agent.run(
|
105 |
final_lyrics = result["Task outcome (extremely detailed version)"]
|
106 |
done = True
|
107 |
except Exception as e:
|
@@ -110,10 +94,20 @@ def main():
|
|
110 |
|
111 |
if final_lyrics:
|
112 |
st.success("Lyrics retrieved successfully!")
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
else:
|
115 |
st.error("Failed to retrieve lyrics after multiple attempts.")
|
116 |
|
117 |
if __name__ == "__main__":
|
118 |
main()
|
119 |
-
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import HfApiEngine
|
3 |
+
from transformers.agents import ReactCodeAgent, ReactJsonAgent, ManagedAgent
|
4 |
from transformers.agents.search import DuckDuckGoSearchTool, VisitWebpageTool
|
5 |
from huggingface_hub import login
|
6 |
|
|
|
62 |
# Streamlit App
|
63 |
def main():
|
64 |
st.title("Lyrics Finder App 🎵")
|
65 |
+
st.write("Enter the name of the song and optionally the artist to retrieve the lyrics.")
|
66 |
|
67 |
authenticate_hf()
|
68 |
manager_agent = initialize_agents()
|
69 |
|
70 |
+
# Input for user queries
|
71 |
+
custom_query = st.text_input("Enter your song and artist (e.g., 'Search for Pelo Suelto by Elsa y Elmar')", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
if st.button("Find Lyrics"):
|
74 |
+
if custom_query.strip() == "":
|
75 |
+
st.error("Please enter a valid song and artist name!")
|
76 |
else:
|
77 |
st.write("Processing your request, please wait...")
|
78 |
with st.spinner("Agents are working hard to find the lyrics..."):
|
|
|
85 |
|
86 |
while not done and attempts < max_attempts:
|
87 |
try:
|
88 |
+
result = manager_agent.run(custom_query)
|
89 |
final_lyrics = result["Task outcome (extremely detailed version)"]
|
90 |
done = True
|
91 |
except Exception as e:
|
|
|
94 |
|
95 |
if final_lyrics:
|
96 |
st.success("Lyrics retrieved successfully!")
|
97 |
+
|
98 |
+
# Display lyrics in a larger text area
|
99 |
+
st.text_area("Lyrics Output", final_lyrics, height=400)
|
100 |
+
|
101 |
+
# Button to download lyrics as a text file
|
102 |
+
lyrics_file = f"{custom_query.replace(' ', '_')}_lyrics.txt"
|
103 |
+
st.download_button(
|
104 |
+
label="Download Lyrics as .txt",
|
105 |
+
data=final_lyrics,
|
106 |
+
file_name=lyrics_file,
|
107 |
+
mime="text/plain"
|
108 |
+
)
|
109 |
else:
|
110 |
st.error("Failed to retrieve lyrics after multiple attempts.")
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
main()
|
|