실시간 채팅 인터페이스
필요한 모듈 설치하기
!pip install openai
!pip install gradio
실시간 채팅 인터페이스
import gradio as gr
import time
def chatbot_response(message, history):
# 간단한 챗봇 로직
responses = [
f"You said: {message}",
"That's interesting! Tell me more.",
"I understand. How can I help?",
"Thanks for sharing that with me."
]
import random
bot_response = random.choice(responses)
history.append([message, bot_response])
return history, ""
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
gr.Markdown("# 💬 Smart Chat Assistant")
chatbot = gr.Chatbot(
label="Chat History",
height=300,
show_label=False
)
with gr.Row():
msg = gr.Textbox(
label="Message",
placeholder="Type your message...",
show_label=False,
scale=4
)
send_btn = gr.Button("Send", variant="primary", scale=1)
# 채팅 기능
def send_message(message, history):
return chatbot_response(message, history)
send_btn.click(
send_message,
inputs=[msg, chatbot],
outputs=[chatbot, msg]
)
msg.submit(
send_message,
inputs=[msg, chatbot],
outputs=[chatbot, msg]
)
demo.launch()