yabramuvdi commited on
Commit
0e783cf
·
verified ·
1 Parent(s): e766939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -17
app.py CHANGED
@@ -23,7 +23,10 @@ def initialize_agents():
23
  )
24
 
25
  # Agent 2: Perform a web search
26
- find_lyrics_site_agent = ReactCodeAgent(tools=[VisitWebpageTool()], llm_engine=llm_engine)
 
 
 
27
  managed_find_lyrics_site_agent = ManagedAgent(
28
  agent=find_lyrics_site_agent,
29
  name="find_lyrics_site",
@@ -31,9 +34,11 @@ def initialize_agents():
31
  )
32
 
33
  # Agent 3: Extract lyrics from webpage
34
- web_parsing_agent = ReactCodeAgent(tools=[VisitWebpageTool()],
35
- llm_engine=llm_engine,
36
- additional_authorized_imports=['requests', 'bs4'])
 
 
37
  managed_web_parsing_agent = ManagedAgent(
38
  agent=web_parsing_agent,
39
  name="web_parsing_lyrics",
@@ -65,26 +70,52 @@ def initialize_agents():
65
  # Streamlit App
66
  def main():
67
  st.title("Lyrics Finder App 🎵")
68
- st.write("Enter the name of the song and optionally the artist to retrieve the lyrics.")
69
 
70
  authenticate_hf()
71
  manager_agent = initialize_agents()
72
 
73
- # User input
74
- user_query = st.text_input("Enter the song and/or artist (e.g., 'Shape of You by Ed Sheeran')", "")
 
 
 
 
 
 
 
 
 
 
75
 
76
  if st.button("Find Lyrics"):
77
- if user_query.strip() == "":
78
- st.error("Please enter a valid song or artist name!")
79
  else:
80
- try:
81
- st.write("Processing your request, please wait...")
82
- with st.spinner("Agents are working hard to find the lyrics..."):
83
- result = manager_agent.run(user_query)
84
- st.success("Lyrics retrieved successfully!")
85
- st.markdown(f"### Lyrics for your song\n{result}")
86
- except Exception as e:
87
- st.error(f"An error occurred: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  if __name__ == "__main__":
90
  main()
 
 
23
  )
24
 
25
  # Agent 2: Perform a web search
26
+ find_lyrics_site_agent = ReactCodeAgent(
27
+ tools=[DuckDuckGoSearchTool()],
28
+ llm_engine=llm_engine
29
+ )
30
  managed_find_lyrics_site_agent = ManagedAgent(
31
  agent=find_lyrics_site_agent,
32
  name="find_lyrics_site",
 
34
  )
35
 
36
  # Agent 3: Extract lyrics from webpage
37
+ web_parsing_agent = ReactCodeAgent(
38
+ tools=[VisitWebpageTool()],
39
+ llm_engine=llm_engine,
40
+ additional_authorized_imports=['requests', 'bs4']
41
+ )
42
  managed_web_parsing_agent = ManagedAgent(
43
  agent=web_parsing_agent,
44
  name="web_parsing_lyrics",
 
70
  # Streamlit App
71
  def main():
72
  st.title("Lyrics Finder App 🎵")
73
+ st.write("Enter the name of the song and optionally the artist to retrieve the lyrics, or use one of the example queries below.")
74
 
75
  authenticate_hf()
76
  manager_agent = initialize_agents()
77
 
78
+ # Default examples
79
+ examples = [
80
+ "Search for Pelo Suelto by Elsa y Elmar",
81
+ "Find the lyrics to Shape of You by Ed Sheeran",
82
+ "Get the lyrics for Hips Don't Lie by Shakira",
83
+ ]
84
+
85
+ selected_example = st.selectbox("Select an example query:", [""] + examples)
86
+ custom_query = st.text_input("Or enter your own song and artist (e.g., 'Shape of You by Ed Sheeran')", "")
87
+
88
+ # Determine the task
89
+ task = selected_example if selected_example else custom_query
90
 
91
  if st.button("Find Lyrics"):
92
+ if task.strip() == "":
93
+ st.error("Please select an example or enter a valid song and artist name!")
94
  else:
95
+ st.write("Processing your request, please wait...")
96
+ with st.spinner("Agents are working hard to find the lyrics..."):
97
+
98
+ # Retry logic
99
+ max_attempts = 5
100
+ done = False
101
+ attempts = 0
102
+ final_lyrics = None
103
+
104
+ while not done and attempts < max_attempts:
105
+ try:
106
+ result = manager_agent.run(task)
107
+ final_lyrics = result["Task outcome (extremely detailed version)"]
108
+ done = True
109
+ except Exception as e:
110
+ st.warning(f"Attempt {attempts + 1}/{max_attempts} failed: {e}")
111
+ attempts += 1
112
+
113
+ if final_lyrics:
114
+ st.success("Lyrics retrieved successfully!")
115
+ st.markdown(f"### Lyrics for your song\n{final_lyrics}")
116
+ else:
117
+ st.error("Failed to retrieve lyrics after multiple attempts.")
118
 
119
  if __name__ == "__main__":
120
  main()
121
+