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

Create app.py

Browse files

Copied from preplexity.ai so not sure if is good

Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import Conversation, pipeline
3
+
4
+ # Example group recommendation database
5
+ GROUP_DB = [
6
+ {"group": "Red Velvet", "style": "pop"},
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()