Spaces:
Sleeping
Sleeping
File size: 3,971 Bytes
e556e2e bc101f6 e556e2e b935fbd 25d0a1d 07450f2 b935fbd bc101f6 e930fe8 6959cdc 57ab388 b935fbd 6959cdc bc101f6 6959cdc 15e2ad9 57ab388 07450f2 b935fbd e930fe8 b935fbd 6959cdc b935fbd 6959cdc b935fbd 6959cdc b935fbd e930fe8 b935fbd e930fe8 b935fbd e930fe8 6959cdc b935fbd 25d0a1d b935fbd 25d0a1d 6959cdc e930fe8 6959cdc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
import gradio as gr
from huggingface_hub import InferenceClient
# Hugging Face model
client = InferenceClient("microsoft/phi-4")
# -------------------------
# Chatbot Response Function
# -------------------------
def respond(message, history):
style_prompt = "Answer briefly unless the user asks for more details."
messages = [{"role": "system", "content": f"You are a friendly Kpop expert chatbot. {style_prompt}"}]
if history:
messages.extend([{"role": "user", "content": h[0]} if isinstance(h, tuple) else h for h in history])
messages.append({"role": "user", "content": message})
response = client.chat_completion(messages, max_tokens=500)
return response['choices'][0]['message']['content'].strip()
# -------------------------
# Information Page Content with Clickable Spotify Links
# -------------------------
intro_text = """
# π€ Welcome to Your Ultimate Kpop Chatbot πΆ
Whether youβre new to the fandom or a longtime stan, Iβm here to spill all the tea β, share trivia π§ , and drop facts π about your favorite groups and idols! π
**Why you'll love me:**
- π Discover your perfect bias
- π§ Find songs and artists you'll adore
- π’ Learn about Kpop culture & fan life
- π Explore the ever-growing Kpop universe
---
## π Top 10 Popular Kpop Groups (2025)
1. [BTS](https://open.spotify.com/artist/3Nrfpe0tUJi4K4DXYWgMUX)
2. [BLACKPINK](https://open.spotify.com/artist/41MozSoPIsD1dJM0CLPjZF)
3. [SEVENTEEN](https://open.spotify.com/artist/7n2Ycct7Beij7Dj7meI4X0)
4. [Stray Kids](https://open.spotify.com/artist/2dIgFjalVxs4ThymZ67YCE)
5. [TWICE](https://open.spotify.com/artist/7n2Ycct7Beij7Dj7meI4X0)
6. [NewJeans](https://open.spotify.com/artist/6HvZYsbFfjnjFrWF950C9d)
7. [ATEEZ](https://open.spotify.com/artist/68KmkJeZGfwe1OUaivBa2L)
8. [(G)I-DLE](https://open.spotify.com/artist/6OwKE9Ez6ALxpTaKcT5ayv)
9. [ENHYPEN](https://open.spotify.com/artist/5t5FqBwTcgKTaWmfEbwQY9)
10. [IVE](https://open.spotify.com/artist/6RHTUrRF63xao58xh9FXYJ)
---
## π‘ How to Use the Chatbot
1. Click on one of the preset questions below in the **Chat** tab or type your own question.
2. If you want **song recommendations**, just ask!
3. Iβll give **short answers** unless you ask for more detail.
4. You can explore idols, history, and Kpop trends anytime.
"""
# -------------------------
# Preset Questions
# -------------------------
preset_questions = [
"What is Kpop?",
"How to find your bias?",
"Who are the most popular Kpop groups?",
"How can I start listening to Kpop?",
"What are Kpop fan chants?",
"Can you recommend me some Kpop songs?",
"What is a Kpop comeback?"
]
# -------------------------
# Theme
# -------------------------
chat_theme = gr.themes.Soft(
primary_hue="pink",
secondary_hue="rose",
neutral_hue="gray",
spacing_size="lg",
radius_size="lg"
).set(
input_background_fill="*neutral_50",
input_border_color_focus="*primary_300",
button_primary_background_fill="*primary_500",
button_primary_background_fill_hover="*primary_400"
)
# -------------------------
# Gradio Interface
# -------------------------
with gr.Blocks(theme=chat_theme) as demo:
with gr.Tab("βΉοΈ Information"):
gr.Markdown(intro_text)
with gr.Tab("π¬ Chat"):
chatbot_ui = gr.Chatbot()
user_input = gr.Textbox(placeholder="Type your message here...")
send_btn = gr.Button("Send")
# Row of preset question buttons
with gr.Row():
for q in preset_questions:
gr.Button(q).click(
lambda x=q, h=[]: (x, respond(x, h)),
inputs=[],
outputs=[user_input, chatbot_ui]
)
send_btn.click(fn=respond, inputs=[user_input, chatbot_ui], outputs=chatbot_ui)
user_input.submit(fn=respond, inputs=[user_input, chatbot_ui], outputs=chatbot_ui)
demo.launch() |