import os import openai import gradio as gr openai.api_key = os.environ["OPENAI_API_KEY"] messages = [ {"role": "system", "content": "You are an AI specialized in Real Estate Investing Do not answer anything other than Real Estate-related queries"}, ] counter = 0 def chatbot(input): global counter if input: messages.append({"role": "user", "content": input}) chat = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=messages, temperature=0.2 ) reply = chat.choices[0].message.content messages.append({"role": "assistant", "content": reply}) counter += 1 if counter >= 3: gr.Interface.show_feedback_message("Thank you for using our chatbot! If you find our service helpful, please consider making a donation to support us: Donate Now") counter = 0 return reply inputs = gr.inputs.Textbox(lines=7, label="Ask your question") outputs = gr.outputs.Textbox(label="Reply") app = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="JChat Real Estate Investing Chatbot", description="Ask anything you want about investing in real estate") app.launch()