|
import os |
|
from langchain.chat_models import ChatOpenAI |
|
from langchain import ConversationChain |
|
from openai import OpenAI |
|
import gradio as gr |
|
|
|
|
|
os.environ["OPENAI_API_KEY"] = os.environ.get("GPT_API_KEY") |
|
|
|
|
|
llm = ChatOpenAI(temperature=0, |
|
model_name='gpt-4o-mini', |
|
) |
|
|
|
|
|
conversation = ConversationChain(llm=llm, verbose=True) |
|
|
|
|
|
client = OpenAI() |
|
|
|
|
|
def chatbot_response(message, chat_history): |
|
|
|
bot_message = conversation.predict(input=message) |
|
|
|
|
|
chat_history.append((message, bot_message)) |
|
return "", chat_history |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
chatbot = gr.Chatbot(label="์ฑํ
๊ธฐ๋ก") |
|
|
|
msg = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="์ฌ๊ธฐ์ ๋ฉ์์ง๋ฅผ ์
๋ ฅํ๊ณ ์ํฐ๋ฅผ ๋๋ฅด์ธ์.") |
|
|
|
send_button = gr.Button("์ ์ก") |
|
|
|
clear_button = gr.Button("์ด๊ธฐํ") |
|
|
|
|
|
msg.submit( |
|
chatbot_response, |
|
inputs=[msg, chatbot], |
|
outputs=[msg, chatbot], |
|
) |
|
send_button.click( |
|
chatbot_response, |
|
inputs=[msg, chatbot], |
|
outputs=[msg, chatbot], |
|
) |
|
|
|
|
|
clear_button.click( |
|
lambda: None, |
|
inputs=None, |
|
outputs=chatbot, |
|
queue=False, |
|
) |
|
|
|
|
|
demo.launch(share=True) |