| |
| """Untitled1.ipynb |
| |
| Automatically generated by Colab. |
| |
| Original file is located at |
| https://colab.research.google.com/drive/1huUmrgIbG1wwEKxs3zsCdRNir_IY5ICf |
| """ |
|
|
| import os |
|
|
| from openai import OpenAI |
| import openai |
|
|
| openai_api_key = os.getenv("OPENAI_API_KEY") |
|
|
| client = openai.OpenAI(api_key = openai_api_key) |
|
|
| def openai_chat(text): |
| from openai import OpenAI |
|
|
| completion = client.chat.completions.create( |
| model="gpt-4", |
| messages=[ |
| {"role": "system", "content": "너는 전문상담가고 긍정적으로 답변해야해"}, |
| {"role": "user", "content": text} |
| ] |
| ) |
|
|
| return completion.choices[0].message.content |
|
|
| openai_chat("한글은 누가 만들었어?") |
|
|
| import gradio as gr |
|
|
| with gr.Blocks() as demo: |
| Q = gr.Textbox(label="질문질문", placeholder="질문 넣어라!") |
| btn = gr.Button("블룸블룸") |
| A = gr.TextArea(label="답답", placeholder="GPT가 열일 중 입니다.") |
|
|
| btn.click(openai_chat, inputs=Q, outputs=A) |
|
|
| demo.launch() |