KWK25 commited on
Commit
ac75bf7
·
verified ·
1 Parent(s): 678b366

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -7,42 +7,48 @@ 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
- pip install transformers torch
16
-
17
- def custom_kpop_response(user_input, history):
18
- user_input_lower = user_input.lower()
19
 
20
- # Greeting detection
 
 
21
  greeting = ""
 
 
22
  if any(greet in user_input_lower for greet in ["hi", "hello", "hey"]):
23
  greeting = "Hi there! Welcome to K-pop world! "
24
 
25
- # Custom recommendation
26
  if ("taylor swift" in user_input_lower or
27
  ("pop" in user_input_lower and "kpop" in user_input_lower)):
28
  recommendation = (
29
- "If you like Taylor Swift's pop style, you might enjoy K-pop groups like "
30
- "Red Velvet, TWICE, or BLACKPINK! Theyre known for catchy melodies and energetic choreography."
31
  )
32
- history.append((user_input, greeting + recommendation))
 
33
  return "", history
34
 
35
- # Fallback to model
36
- result = chatbot(user_input, max_length=100)
37
  bot_reply = greeting + result[0]['generated_text']
38
-
39
- history.append((user_input, bot_reply))
40
  return "", history
41
 
42
  iface = gr.ChatInterface(
43
  fn=custom_kpop_response,
44
  title="K-Pop Genie Chatbot",
45
- description="Say hi! Ask for K-pop groups or songs similar to your Western favorites."
46
  )
47
 
48
- iface.launch()
 
 
 
7
  {"group": "TWICE", "style": "pop"},
8
  {"group": "BLACKPINK", "style": "pop"},
9
  {"group": "BTS", "style": "pop"},
10
+ # Add more groups if you want!
11
  ]
12
 
13
+ # Use the BlenderBot small model (CPU & RAM friendly)
14
+ chatbot = pipeline(
15
+ "text2text-generation",
16
+ model="facebook/blenderbot-400M-distill",
17
+ device=-1 # Force CPU (for Hugging Face CPU Spaces)
18
+ )
 
19
 
20
+ def custom_kpop_response(message, history):
21
+ """Gradio expects (message, history) and returns (response, history)."""
22
+ user_input_lower = message.lower()
23
  greeting = ""
24
+
25
+ # Greeting logic
26
  if any(greet in user_input_lower for greet in ["hi", "hello", "hey"]):
27
  greeting = "Hi there! Welcome to K-pop world! "
28
 
29
+ # Custom K-pop pop recommendation
30
  if ("taylor swift" in user_input_lower or
31
  ("pop" in user_input_lower and "kpop" in user_input_lower)):
32
  recommendation = (
33
+ "If you like Taylor Swift's pop style, try K-pop groups like Red Velvet, "
34
+ "TWICE, or BLACKPINK! They're known for catchy melodies and energetic choreography."
35
  )
36
+ bot_reply = greeting + recommendation
37
+ history.append((message, bot_reply))
38
  return "", history
39
 
40
+ # Fallback to BlenderBot for other questions
41
+ result = chatbot(message, max_length=100)
42
  bot_reply = greeting + result[0]['generated_text']
43
+ history.append((message, bot_reply))
 
44
  return "", history
45
 
46
  iface = gr.ChatInterface(
47
  fn=custom_kpop_response,
48
  title="K-Pop Genie Chatbot",
49
+ description="Say hi! Ask for K-pop groups, or songs similar to your Western favorites."
50
  )
51
 
52
+ if __name__ == "__main__":
53
+ iface.launch()
54
+