Saurabh46 commited on
Commit
ffe10e4
·
1 Parent(s): 30ef23d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -8
app.py CHANGED
@@ -16,32 +16,25 @@ def construct_index(directory_path):
16
 
17
  index = GPTVectorStoreIndex.from_documents(docs, service_context=service_context)
18
 
19
- #Directory in which the indexes will be stored
20
  index.storage_context.persist(persist_dir="indexes")
21
 
22
  return index
23
 
24
  def chatbot(input_text):
25
 
26
- # rebuild storage context
27
  storage_context = StorageContext.from_defaults(persist_dir="indexes")
28
-
29
- #load indexes from directory using storage_context
30
  query_engne = load_index_from_storage(storage_context).as_query_engine()
31
 
32
  response = query_engne.query(input_text)
33
 
34
- #returning the response
35
  return response.response
36
 
37
- #Creating the web UIusing gradio
38
  iface = gradio.Interface(fn=chatbot,
39
  inputs=gradio.inputs.Textbox(lines=4, label="Enter your question here"),
40
  outputs=gradio.outputs.Textbox(label="Generated Text"),
41
  title="Custom-trained AI Chatbot")
42
 
43
- #Constructing indexes based on the documents in trainingData folder
44
  index = construct_index("trainingData")
45
 
46
- #launching the web UI using gradio
47
  iface.launch()
 
16
 
17
  index = GPTVectorStoreIndex.from_documents(docs, service_context=service_context)
18
 
 
19
  index.storage_context.persist(persist_dir="indexes")
20
 
21
  return index
22
 
23
  def chatbot(input_text):
24
 
 
25
  storage_context = StorageContext.from_defaults(persist_dir="indexes")
26
+
 
27
  query_engne = load_index_from_storage(storage_context).as_query_engine()
28
 
29
  response = query_engne.query(input_text)
30
 
 
31
  return response.response
32
 
 
33
  iface = gradio.Interface(fn=chatbot,
34
  inputs=gradio.inputs.Textbox(lines=4, label="Enter your question here"),
35
  outputs=gradio.outputs.Textbox(label="Generated Text"),
36
  title="Custom-trained AI Chatbot")
37
 
 
38
  index = construct_index("trainingData")
39
 
 
40
  iface.launch()