GeorgiaChatBot / app.py
pd4consultingmyles's picture
Update app.py
f9e1188
from gpt_index import (
SimpleWebPageReader,
WikipediaReader,
GPTListIndex,
GPTSimpleVectorIndex,
LLMPredictor,
QuestionAnswerPrompt,
PromptHelper
)
from langchain.chat_models import ChatOpenAI
from langchain.prompts.chat import ChatPromptTemplate, SystemMessagePromptTemplate
import gradio as gr
import sys
import os
# openai api key
os.environ["OPENAI_API_KEY"] = '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'
def chatbot(input_text):
# preset prompt
query_str = "How do I renew my driver's license?"
QA_PROMPT_TMPL = (
"You are an AI specialized in Georgia.\n"
"If a query does not involve Georgia, say you can't answer the query but then relate the answer to Georgia.\n"
"If you cannot relate the query to Georgia, do not answer it.\n"
"We have provided context information below. \n"
"---------------------\n"
"{context_str}"
"\n---------------------\n"
"Given this information, please give a detailed answer to the question: {query_str}\n"
)
QA_PROMPT = QuestionAnswerPrompt(QA_PROMPT_TMPL)
# Takes in the input from the user to deliver responses
index = GPTSimpleVectorIndex.load_from_disk('index.json')
response = index.query(input_text, text_qa_template = QA_PROMPT)
return response.response
# creates the interface for the user to interact with the chatbot
iface = gr.Interface(fn=chatbot,
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
outputs="text",
title="PD4 Chatbot based on Georgia.gov")
iface.launch()