KWK25 commited on
Commit
9d87073
·
verified ·
1 Parent(s): b89ff96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -18
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from transformers import Conversation, pipeline
3
 
4
  # Example group recommendation database
5
  GROUP_DB = [
@@ -7,35 +7,40 @@ GROUP_DB = [
7
  {"group": "TWICE", "style": "pop"},
8
  {"group": "BLACKPINK", "style": "pop"},
9
  {"group": "BTS", "style": "pop"},
10
- # Add more groups with styles!
11
  ]
12
 
13
- # Conversational model from Hugging Face
14
- chatbot = pipeline(model="facebook/blenderbot-400M-distill", task="conversational")
15
 
16
  def custom_kpop_response(user_input, history):
17
  user_input_lower = user_input.lower()
18
- # Detect greeting and genre hint from the user
 
 
19
  if any(greet in user_input_lower for greet in ["hi", "hello", "hey"]):
20
  greeting = "Hi there! Welcome to K-pop world! "
21
- else:
22
- greeting = ""
23
- # Custom pop music recommendation logic
24
  if ("taylor swift" in user_input_lower or
25
  ("pop" in user_input_lower and "kpop" in user_input_lower)):
26
- recommendation = ("If you like Taylor Swift's pop style, "
27
- "you might enjoy K-pop groups like Red Velvet, TWICE, or BLACKPINK! "
28
- "They’re known for catchy melodies and energetic choreography.")
29
- return greeting + recommendation
30
- # Fallback: let chatbot handle other cases
31
- conversation = Conversation(user_input)
32
- result = chatbot(conversation)
33
- # Just return chatbot's generated text
34
- return greeting + conversation.generated_responses[-1]
 
 
 
 
35
 
36
  iface = gr.ChatInterface(
37
- custom_kpop_response,
38
  title="K-Pop Genie Chatbot",
39
  description="Say hi! Ask for K-pop groups or songs similar to your Western favorites."
40
  )
 
41
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
  # Example group recommendation database
5
  GROUP_DB = [
 
7
  {"group": "TWICE", "style": "pop"},
8
  {"group": "BLACKPINK", "style": "pop"},
9
  {"group": "BTS", "style": "pop"},
 
10
  ]
11
 
12
+ # Use text2text pipeline instead of deprecated conversational task
13
+ chatbot = pipeline("text2text-generation", model="facebook/blenderbot-400M-distill")
14
 
15
  def custom_kpop_response(user_input, history):
16
  user_input_lower = user_input.lower()
17
+
18
+ # Greeting detection
19
+ greeting = ""
20
  if any(greet in user_input_lower for greet in ["hi", "hello", "hey"]):
21
  greeting = "Hi there! Welcome to K-pop world! "
22
+
23
+ # Custom recommendation
 
24
  if ("taylor swift" in user_input_lower or
25
  ("pop" in user_input_lower and "kpop" in user_input_lower)):
26
+ recommendation = (
27
+ "If you like Taylor Swift's pop style, you might enjoy K-pop groups like "
28
+ "Red Velvet, TWICE, or BLACKPINK! They’re known for catchy melodies and energetic choreography."
29
+ )
30
+ history.append((user_input, greeting + recommendation))
31
+ return "", history
32
+
33
+ # Fallback to model
34
+ result = chatbot(user_input, max_length=100)
35
+ bot_reply = greeting + result[0]['generated_text']
36
+
37
+ history.append((user_input, bot_reply))
38
+ return "", history
39
 
40
  iface = gr.ChatInterface(
41
+ fn=custom_kpop_response,
42
  title="K-Pop Genie Chatbot",
43
  description="Say hi! Ask for K-pop groups or songs similar to your Western favorites."
44
  )
45
+
46
  iface.launch()