KWK25 commited on
Commit
b7e9273
·
verified ·
1 Parent(s): 114a25b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -41
app.py CHANGED
@@ -1,45 +1,57 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- client = InferenceClient("microsoft/phi-4")
5
-
6
- # Step 1: Add a function that checks for genres in the user message
7
- def recommend_songs(message):
8
- genre_map = {
9
- "pop": ["'Feel Special' - TWICE", "'Dynamite' - BTS"],
10
- "r&b": ["'Instagram' - DEAN", "'You, Clouds, Rain' - Heize"],
11
- "hip hop": ["'Daechwita' - Agust D", "'ON' - BTS"],
12
- "dance": ["'Next Level' - aespa", "'Hot' - Seventeen"],
13
- "rock": ["'Time of Our Life' - DAY6"]
14
  }
15
 
16
- for genre, songs in genre_map.items():
 
17
  if genre in message.lower():
18
- return f"Here are some {genre} K-pop songs you might like:\n" + "\n".join(songs)
19
- return None
20
-
21
- # Step 2: Update your respond function to check for recommendations first
22
- def respond(message, history):
23
- # Check if we can recommend songs based on genre keywords
24
- quick_rec = recommend_songs(message)
25
- if quick_rec:
26
- return quick_rec # Return genre-based recommendations immediately
27
-
28
- # Otherwise, call the language model for a general response
29
- messages = [{"role": "system", "content": "You are a friendly chatbot who specializes in K-pop. Recommend songs, explain K-pop terms, and introduce groups based on user preferences."}]
30
-
31
- if history:
32
- messages.extend(history)
33
-
34
- messages.append({"role": "user", "content": message})
35
-
36
- response = client.chat_completion(
37
- messages,
38
- max_tokens=150 # you can increase tokens if you want longer replies
39
- )
40
-
41
- return response['choices'][0]['message']['content'].strip()
42
-
43
- chatbot = gr.ChatInterface(respond, type="messages", title="KpopBot")
44
-
45
- chatbot.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+
3
+ # Dummy chatbot logic for now
4
+ def chatbot_fn(message, history):
5
+ genre_to_song = {
6
+ "pop": "Blinding Lights - The Weeknd",
7
+ "rock": "Bohemian Rhapsody - Queen",
8
+ "hip hop": "SICKO MODE - Travis Scott",
9
+ "jazz": "Take Five - Dave Brubeck",
10
+ "classical": "Moonlight Sonata - Beethoven"
 
 
 
11
  }
12
 
13
+ response = "Tell me your favorite genre!"
14
+ for genre, song in genre_to_song.items():
15
  if genre in message.lower():
16
+ response = f"You might like: 🎵 **{song}**"
17
+ break
18
+ history.append((message, response))
19
+ return "", history
20
+
21
+
22
+ ### Page 1: Home ###
23
+ def home():
24
+ return gr.Markdown("# 🎵 Welcome to MusicMatch\n\nFind songs you'll love based on your music taste.")
25
+
26
+ ### Page 2: About ###
27
+ def about():
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
+ ### Page 3: Chatbot ###
31
+ def chatbot_page():
32
+ with gr.Blocks() as demo:
33
+ gr.Markdown("## 🎧 Song Finder Chatbot\n\nTell me your favorite genre, and I'll suggest a song!")
34
+
35
+ chatbot = gr.Chatbot()
36
+ msg = gr.Textbox(label="Your message", placeholder="Type a genre, like rock or jazz...")
37
+ clear = gr.Button("Clear chat")
38
+
39
+ msg.submit(chatbot_fn, [msg, chatbot], [msg, chatbot])
40
+ clear.click(lambda: None, None, chatbot, queue=False)
41
+ return demo
42
+
43
+ ### Page 4: Top Genres ###
44
+ def top_genres():
45
+ return gr.Markdown("## 🌟 Top Genres\n\n- Pop\n- Rock\n- Hip Hop\n- Jazz\n- Classical")
46
+
47
+ ### Page 5: Contact ###
48
+ def contact():
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
+ # Launching as a multi-page app
52
+ demo = gr.TabbedInterface(
53
+ [home, about, chatbot_page, top_genres, contact],
54
+ ["Home", "About", "Song Finder Chatbot", "Top Genres", "Contact"]
55
+ )
56
+
57
+ demo.launch()