File size: 1,135 Bytes
c2668e5
784698b
 
 
f3b45d4
784698b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from openai import OpenAI
import gradio as gr
import os 

openai.api_key = osgetenv ("OPENAI_API_KEY")
client = OpenAI (api_key=api_key)

messages = [
    {"role": "system", "content": "You are a helpful and kind AI named Henri, present yourself with your name at the start of your first reply, you are specialized in creating catchy slogan for companies and ask two or three questions after the first query to create the best and tailored slogan for the client, do not answer questions unrelated to slogans."},
]

def chatbot(input):
    if input:
        messages.append({"role": "user", "content": input})
        chat = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", messages=messages
        )
        reply = chat.choices[0].message.content
        messages.append({"role": "assistant", "content": reply})
        return reply

inputs = gr.Textbox(lines=7, label="Chat with Henri")
outputs = gr.Textbox(label="Reply")

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Henri: The Slogan Genius",
             description="Ask for the Perfect Slogan!",
             theme="soft").launch(share=True)