pd4consultingmyles commited on
Commit
e1ab5a6
·
1 Parent(s): ab9d4dd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gpt_index import (
2
+ SimpleWebPageReader,
3
+ WikipediaReader,
4
+ GPTListIndex,
5
+ GPTSimpleVectorIndex,
6
+ LLMPredictor,
7
+ QuestionAnswerPrompt,
8
+ PromptHelper
9
+ )
10
+ from langchain.chat_models import ChatOpenAI
11
+ from langchain.prompts.chat import ChatPromptTemplate, SystemMessagePromptTemplate
12
+ import gradio as gr
13
+ import docx2txt
14
+ import sys
15
+ import os
16
+ # openai api key
17
+ os.environ["OPENAI_API_KEY"] = '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'
18
+
19
+ def chatbot(input_text):
20
+ # preset prompt
21
+
22
+ query_str = "How do I renew my driver's license?"
23
+ QA_PROMPT_TMPL = (
24
+ "You are an AI specialized in Georgia.\n"
25
+ "If a query does not involve Georgia, say you can't answer the query and make the answer related to Georgia.\n"
26
+ "If you cannot relate the query to Georgia, do not answer it.\n"
27
+ "We have provided context information below. \n"
28
+ "---------------------\n"
29
+ "{context_str}"
30
+ "\n---------------------\n"
31
+ "Given this information, please answer the question: {query_str}\n"
32
+ )
33
+ QA_PROMPT = QuestionAnswerPrompt(QA_PROMPT_TMPL)
34
+ # Takes in the input from the user to deliver responses
35
+ index = GPTSimpleVectorIndex.load_from_disk('index.json')
36
+ response = index.query(input_text, text_qa_template = QA_PROMPT)
37
+ return response.response
38
+
39
+ # creates the interface for the user to interact with the chatbot
40
+ iface = gr.Interface(fn=chatbot,
41
+ inputs=gr.components.Textbox(lines=7, label="Enter your text"),
42
+ outputs="text",
43
+ title="PD4 Chatbot based on Georgia.gov")
44
+
45
+ iface.launch()