File size: 1,303 Bytes
980a65f
 
1d56af5
a7debd6
 
980a65f
b10d957
980a65f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d5614cd
980a65f
 
d5614cd
 
221beb1
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
import openai
import gradio as gr
import os 
from dotenv import load_dotenv
load_dotenv()

openai.api_key = os.getenv("OPEN_AI_KEY")

messages = [
    {"role": "system", "content": "You are an AI assistant that only gives responses from the website www.thebetterindia.com and you help people make decisions about how to make a difference in others' lives. You also provide the relevant links from that website as part of your answers."},
]

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=7, label="Chat with The Better India's AI bot")
outputs = gr.outputs.Textbox(label="Reply")

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="The Better India's AI Bot",
             description="Anything you want to, from the world of The Better India. Sample questions include >>> where do I donate old toys in Bangalore? >>> stories of water conservation in India >>> any teenagers working in the areas of education? >>> and more",
             theme="compact").launch()