KWK25 commited on
Commit
5420e3a
·
verified ·
1 Parent(s): ac75bf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -53
app.py CHANGED
@@ -1,54 +1,34 @@
1
- import gradio as gr
2
- from transformers import 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 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
 
 
1
+ iimport gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ client = InferenceClient("microsoft/phi-4")
5
+
6
+ def respond(message, history):
7
+ messages = [{"role": "system", "content": "You are a friendly kpop chatbot."}]
8
+ if history:
9
+ messages.extend(history)
10
+ messages.append({"role": "user", "content": message})
11
+ response = client.chat_completion(messages, max_tokens=100)
12
+ return response['choices'][0]['message']['content'].strip()
13
+
14
+ spotify_iframe = """
15
+ <div style="max-width: 720px; margin: 12px auto;">
16
+ <iframe
17
+ data-testid="embed-iframe"
18
+ style="border-radius:12px"
19
+ src="https://open.spotify.com/embed/playlist/2EoheVFjqIxgJMb8VnDRtZ?utm_source=generator&theme=0"
20
+ width="100%"
21
+ height="352"
22
+ frameborder="0"
23
+ allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
24
+ loading="lazy">
25
+ </iframe>
26
+ </div>
27
+ """
28
+
29
+ with gr.Blocks() as demo:
30
+ chatbot = gr.ChatInterface(respond, type="messages", title="Kpop Song Hunters")
31
+ gr.HTML(spotify_iframe)
32
+
33
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34