Spaces:
Running
Running
import gradio as gr | |
from chatbot import respond | |
def chat_respond(message, history): | |
response = respond(message) | |
history.append(f"User: {message}") | |
history.append(f"Kossistant: {response}") | |
return format_history(history), history, "" | |
def format_history(history): | |
html = "<div class='chat-container'>" | |
for i in range(0, len(history) - 1, 2): | |
user = history[i].replace("User: ", "") | |
bot = history[i+1].replace("Kossistant: ", "") | |
html += f""" | |
<div class='message user'> | |
<div class='bubble user-bubble'>{user}</div> | |
</div> | |
<div class='message bot'> | |
<div class='bubble bot-bubble'>{bot}</div> | |
</div> | |
""" | |
html += "</div>" | |
return html | |
import gradio as gr | |
with gr.Blocks(css=""" | |
* { | |
box-sizing: border-box; | |
margin: 0; | |
padding: 0; | |
transition: all 0.3s ease; | |
} | |
body { | |
background-color: #121212; | |
color: #ffffff; | |
font-family: 'Roboto', sans-serif; | |
overflow: hidden; | |
padding: 0; | |
margin: 0; | |
} | |
h1 { | |
font-size: 3rem; | |
color: #00f7ff; | |
text-align: center; | |
margin-top: 40px; | |
text-transform: uppercase; | |
letter-spacing: 3px; | |
animation: glowingText 1.5s infinite alternate; | |
} | |
.chat-container { | |
background-color: #1a1a1a; | |
border-radius: 20px; | |
max-width: 850px; | |
margin: auto; | |
padding: 30px; | |
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3); | |
height: 70vh; | |
display: flex; | |
flex-direction: column; | |
justify-content: flex-end; | |
overflow-y: auto; | |
scrollbar-width: thin; | |
scrollbar-color: #444 #1a1a1a; | |
} | |
.chat-container::-webkit-scrollbar { | |
width: 6px; | |
} | |
.chat-container::-webkit-scrollbar-thumb { | |
background-color: #444; | |
border-radius: 4px; | |
} | |
.chat-wrapper { | |
display: flex; | |
flex-direction: column; | |
gap: 10px; | |
flex-grow: 1; | |
} | |
.message { | |
display: flex; | |
margin-bottom: 20px; | |
animation: slideIn 0.5s ease-out; | |
} | |
.user { | |
justify-content: flex-end; | |
} | |
.bot { | |
justify-content: flex-start; | |
} | |
.bubble { | |
max-width: 75%; | |
padding: 16px; | |
border-radius: 18px; | |
font-size: 1rem; | |
line-height: 1.6; | |
word-break: break-word; | |
white-space: pre-wrap; | |
position: relative; | |
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2); | |
transition: transform 0.2s ease, background-color 0.3s ease; | |
} | |
.user-bubble { | |
background-color: #00796B; | |
color: white; | |
border-bottom-right-radius: 0; | |
} | |
.bot-bubble { | |
background-color: #2F3136; | |
color: white; | |
border-bottom-left-radius: 0; | |
} | |
.bot-bubble:after { | |
content: ''; | |
position: absolute; | |
left: -8px; | |
top: 10px; | |
border: 6px solid transparent; | |
border-right-color: #2F3136; | |
} | |
.user-bubble:after { | |
content: ''; | |
position: absolute; | |
right: -8px; | |
top: 10px; | |
border: 6px solid transparent; | |
border-left-color: #00796B; | |
} | |
.bubble:hover { | |
transform: scale(1.05); | |
} | |
.input-row { | |
display: flex; | |
gap: 10px; | |
margin-top: 15px; | |
} | |
textarea, input[type="text"] { | |
background-color: #2C2C2C; | |
color: black; /* ν μ€νΈ μμ κ²μμμΌλ‘ μμ */ | |
border: 1px solid #555; | |
border-radius: 14px; | |
padding: 12px 16px; | |
font-size: 1rem; | |
flex-grow: 1; | |
} | |
textarea:focus, input[type="text"]:focus { | |
outline: none; | |
border-color: #00f7ff; | |
box-shadow: 0 0 8px #00f7ff55; | |
} | |
button { | |
background-color: #00C896; | |
color: white; | |
font-weight: bold; | |
border: none; | |
border-radius: 14px; | |
padding: 14px 20px; | |
font-size: 1.2rem; | |
transition: background-color 0.3s ease, transform 0.2s ease; | |
} | |
button:hover { | |
background-color: #00a67e; | |
transform: scale(1.05) rotate(2deg); | |
} | |
@keyframes glowingText { | |
0% { text-shadow: 0 0 10px #00f7ff, 0 0 20px #00f7ff, 0 0 30px #00f7ff; } | |
50% { text-shadow: 0 0 20px #00f7ff, 0 0 40px #00f7ff, 0 0 60px #00f7ff; } | |
100% { text-shadow: 0 0 10px #00f7ff, 0 0 20px #00f7ff, 0 0 30px #00f7ff; } | |
} | |
@keyframes slideIn { | |
0% { transform: translateY(10px); opacity: 0; } | |
100% { transform: translateY(0); opacity: 1; } | |
} | |
""") as demo: | |
gr.HTML("<h1>Kossistant μ±λ΄</h1>") | |
with gr.Column(elem_classes="chat-wrapper"): | |
chatbox = gr.HTML(value="", label="λν") | |
with gr.Row(): | |
msg = gr.Textbox(placeholder="λ©μμ§λ₯Ό μ λ ₯νμΈμ", lines=1, scale=8) | |
send_button = gr.Button("μ μ‘", scale=2) | |
state = gr.State([]) | |
send_button.click(chat_respond, inputs=[msg, state], outputs=[chatbox, state, msg]) | |
msg.submit(chat_respond, inputs=[msg, state], outputs=[chatbox, state, msg]) | |
demo.launch(share=True) | |