import openai import gradio as gr import os openai.api_key = os.environ['api_key'] messages = [ {"role": "system", "content": "You are an AI specialized in Marketing and PR. Do not answer anything other than marketing and pr-related queries."}, ] 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.inputs.Textbox(lines=15, label="Post your question below") outputs = gr.outputs.Textbox(label="Reply") gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="SMC AI Chatbot", description="I am happy to assist you on anything related to Marketing and PR information", theme="compact").launch()