Spaces:
Sleeping
Sleeping
| 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() |