ai / app.py
thebetterindia's picture
Update app.py
a7debd6
raw
history blame contribute delete
No virus
1.3 kB
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()