File size: 1,285 Bytes
305e7a4
b1900b6
 
 
305e7a4
b1900b6
 
 
 
d05154c
b1900b6
d05154c
b1900b6
 
4ee3834
dca3208
b1900b6
dca3208
b1900b6
d05154c
 
5dadac1
d05154c
77b94a8
b1900b6
 
 
 
31952eb
4af51de
dca3208
f503b31
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
28
29
30
31
32
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: <a href='https://www.paypal.me/exnav29' target='_blank'>Donate Now</a>")
            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()