Spaces:
Build error
Build error
| import gradio as gr | |
| import os | |
| import openai | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| os.environ["OPENAI_API_KEY"] = os.environ['my_secret'] | |
| def predict(input, history): | |
| history.append({"role": "user", "content": input}) | |
| gpt_response = openai.ChatCompletion.create( | |
| model=model_id, | |
| messages=history | |
| ) | |
| response = gpt_response["choices"][0]["message"]["content"] | |
| history.append({"role": "assistant", "content": response}) | |
| messages = [(history[i]["content"], history[i+1]["content"]) for i in range(1, len(history), 2)] | |
| return messages, history | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot(label="ChatBot") | |
| state = gr.State([{ | |
| "role": "system", | |
| "content": "You are a chatbot for psychological counseling." | |
| }]) | |
| with gr.Row(): | |
| txt = gr.Textbox(show_label=False, placeholder="์๋ด์ ์์ฒญํด๋ณด์ธ์").style(container=False) | |
| txt.submit(predict, [txt, state], [chatbot, state]) | |
| demo.launch(debug=True, share=True) |