|
|
import gradio as gr |
|
|
from huggingface_hub import InferenceClient |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = InferenceClient("microsoft/phi-4") |
|
|
|
|
|
def respond(message, history): |
|
|
|
|
|
|
|
|
messages = [{"role": "system", "content": "You are a friendly kpop expert chatbot."}] |
|
|
|
|
|
if history: |
|
|
messages.extend(history) |
|
|
|
|
|
messages.append({"role": "user", "content": message}) |
|
|
|
|
|
response = client.chat_completion( |
|
|
messages, |
|
|
max_tokens=10000 |
|
|
) |
|
|
|
|
|
return response['choices'][0]['message']['content'].strip() |
|
|
|
|
|
chatbot = gr.ChatInterface(respond, type="messages") |
|
|
|
|
|
title = "Kpop chatbot" |
|
|
|
|
|
topics = """ |
|
|
<div class='big-paragraph'> |
|
|
๐ Hey Kpop fan! <br> |
|
|
Whether youโre new to the fandom or a longtime stan, Iโm your ultimate Kpop buddy here to spill all the tea โ๏ธ, trivia ๐ง , and facts ๐ about your favorite groups and idols! ๐<br><br> |
|
|
Want to find your perfect group or bias? Just ask me! ๐๐ค <br><br> |
|
|
Not only that, if you love an artist outside of Kpop, I can help you discover similar vibes and styles from the amazing world of Kpop too! ๐งโจ<br><br> |
|
|
So whether youโre looking for your first bias or your next obsession, Iโve got you covered. <br> |
|
|
Letโs dive into the colorful, energetic, and ever-growing universe of Kpop together! ๐๐ซ |
|
|
</div> |
|
|
""" |
|
|
disclaimer = "" |
|
|
|
|
|
css = """ |
|
|
.big-text { |
|
|
font-size: 100px; |
|
|
font-weight: bold; |
|
|
} |
|
|
.big-paragraph { |
|
|
font-size: 100px; |
|
|
line-height: 3; |
|
|
} |
|
|
""" |
|
|
|
|
|
|
|
|
with gr.Blocks() as chatbot: |
|
|
with gr.Row(): |
|
|
with gr.Column(scale=1): |
|
|
gr.Markdown(title) |
|
|
gr.Markdown(topics) |
|
|
with gr.Column(scale=2): |
|
|
gr.ChatInterface( |
|
|
fn=respond, |
|
|
type="messages" |
|
|
) |
|
|
with gr.Row(): |
|
|
gr.Markdown(disclaimer) |
|
|
|
|
|
chatbot.launch() |