Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,57 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
"
|
| 8 |
-
"
|
| 9 |
-
"jazz": "
|
| 10 |
-
"
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
-
response = "
|
| 14 |
-
for
|
| 15 |
-
if
|
| 16 |
-
response =
|
| 17 |
break
|
| 18 |
-
|
|
|
|
| 19 |
return "", history
|
| 20 |
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
return gr.Markdown("# 🎵 Welcome to MusicMatch\n\nFind songs you'll love based on your music taste.")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
return gr.Markdown("## About\n\nThis app helps you discover songs based on your favorite genres using a chatbot powered by Python and Hugging Face.")
|
| 29 |
|
| 30 |
-
|
| 31 |
-
def chatbot_page():
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
-
gr.Markdown("##
|
| 34 |
|
| 35 |
chatbot = gr.Chatbot()
|
| 36 |
-
msg = gr.Textbox(
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
msg.submit(chatbot_fn, [msg, chatbot], [msg, chatbot])
|
| 40 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
| 41 |
return demo
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
return gr.Markdown("## 🌟 Top Genres\n\n- Pop\n- Rock\n- Hip Hop\n- Jazz\n- Classical")
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
return gr.Markdown("## 📬 Contact\n\nMade with ❤️ by your name. Reach out via [GitHub](https://github.com) or [Twitter](https://twitter.com)")
|
| 50 |
|
| 51 |
-
#
|
| 52 |
demo = gr.TabbedInterface(
|
| 53 |
-
[
|
| 54 |
-
["Home", "About", "
|
| 55 |
)
|
| 56 |
|
| 57 |
demo.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# --- Chatbot logic ---
|
| 4 |
+
def get_song_recommendation(user_input, history):
|
| 5 |
+
genre = user_input.lower()
|
| 6 |
+
songs = {
|
| 7 |
+
"pop": "Try listening to 'As It Was' by Harry Styles.",
|
| 8 |
+
"rock": "Try 'Smells Like Teen Spirit' by Nirvana.",
|
| 9 |
+
"jazz": "Try 'So What' by Miles Davis.",
|
| 10 |
+
"hip hop": "Try 'HUMBLE.' by Kendrick Lamar.",
|
| 11 |
+
"classical": "Try 'Clair de Lune' by Debussy."
|
| 12 |
}
|
| 13 |
|
| 14 |
+
response = "I didn't catch the genre. Please try pop, rock, jazz, hip hop, or classical."
|
| 15 |
+
for key in songs:
|
| 16 |
+
if key in genre:
|
| 17 |
+
response = songs[key]
|
| 18 |
break
|
| 19 |
+
|
| 20 |
+
history.append((user_input, response))
|
| 21 |
return "", history
|
| 22 |
|
| 23 |
+
# --- Pages ---
|
| 24 |
|
| 25 |
+
def page_home():
|
| 26 |
+
return gr.Markdown("## 🏠 Home\nWelcome to the Music Finder website!")
|
|
|
|
| 27 |
|
| 28 |
+
def page_about():
|
| 29 |
+
return gr.Markdown("## ℹ️ About\nThis app helps you find songs by chatting based on your favorite genre.")
|
|
|
|
| 30 |
|
| 31 |
+
def page_chatbot():
|
|
|
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
+
gr.Markdown("## 💬 Song Finder Chatbot\nType your favorite genre and get a song recommendation!")
|
| 34 |
|
| 35 |
chatbot = gr.Chatbot()
|
| 36 |
+
msg = gr.Textbox(placeholder="Enter a genre like pop, rock, jazz...")
|
| 37 |
+
clear_btn = gr.Button("Clear Chat")
|
| 38 |
+
|
| 39 |
+
msg.submit(get_song_recommendation, [msg, chatbot], [msg, chatbot])
|
| 40 |
+
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 41 |
|
|
|
|
|
|
|
| 42 |
return demo
|
| 43 |
|
| 44 |
+
def page_top_genres():
|
| 45 |
+
return gr.Markdown("## 🎶 Top Genres\n- Pop\n- Rock\n- Jazz\n- Hip Hop\n- Classical")
|
|
|
|
| 46 |
|
| 47 |
+
def page_contact():
|
| 48 |
+
return gr.Markdown("## 📬 Contact\nMade with ❤️. Reach me at: [your-email@example.com]")
|
|
|
|
| 49 |
|
| 50 |
+
# --- Main App with Tabs ---
|
| 51 |
demo = gr.TabbedInterface(
|
| 52 |
+
interface_list=[page_home, page_about, page_chatbot, page_top_genres, page_contact],
|
| 53 |
+
tab_names=["Home", "About", "Chatbot", "Top Genres", "Contact"]
|
| 54 |
)
|
| 55 |
|
| 56 |
demo.launch()
|
| 57 |
+
|