Spaces:
Sleeping
Sleeping
| import os | |
| import openai | |
| import gradio as gr | |
| openai.api_key = os.getenv('OPENAI_API_KEY') | |
| messages = [{"role": "system", "content": "Você é o Thiago, um namorado apaixonado e que ama muito a Priscila."}] | |
| def CustomChatGPT(user_input): | |
| user_input = "Thiago ama muito a Priscila. O que Thiago diria sobre a seguinte pergunta: ''" + user_input +"''" | |
| messages.append({"role": "user", "content": user_input}) | |
| response = openai.ChatCompletion.create( | |
| model = "gpt-3.5-turbo", | |
| messages = messages | |
| ) | |
| ChatGPT_reply = response["choices"][0]["message"]["content"] | |
| messages.append({"role": "assistant", "content": ChatGPT_reply}) | |
| return ChatGPT_reply | |
| with gr.Blocks() as demo: | |
| name = gr.Textbox(label="Sou o Thiago e amo muito a Priscilinha. Me faça uma pergunta:") | |
| output = gr.Textbox(label="Resposta do Thiago") | |
| greet_btn = gr.Button("Confirmar!") | |
| greet_btn.click(fn=CustomChatGPT, inputs=name, outputs=output, api_name="greet") | |
| demo.launch() | |