Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 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 |
-
#
|
| 14 |
-
chatbot = pipeline(model="facebook/blenderbot-400M-distill"
|
| 15 |
|
| 16 |
def custom_kpop_response(user_input, history):
|
| 17 |
user_input_lower = user_input.lower()
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
if any(greet in user_input_lower for greet in ["hi", "hello", "hey"]):
|
| 20 |
greeting = "Hi there! Welcome to K-pop world! "
|
| 21 |
-
|
| 22 |
-
|
| 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 = (
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
#
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|