dtrejopizzo commited on
Commit
c2ea10b
·
1 Parent(s): b8f6b35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -14,29 +14,25 @@ def construct_index(directory_path):
14
 
15
  prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
16
 
17
- llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-4", max_tokens=num_outputs))
18
 
19
  documents = SimpleDirectoryReader(directory_path).load_data()
20
-
21
- index = GPTVectorStoreIndex(documents)
22
-
23
- index.storage_context.persist()
24
 
25
  return index
26
 
27
  def chatbot(input_text):
28
  query_engine = index.as_query_engine()
29
- #index = GPTVectorStoreIndex.load_from_disk('index.json')
30
- response = query_engine.query(input_text, response_mode="compact")
31
  return response.response
32
 
33
  iface = gr.Interface(fn=chatbot,
34
- inputs=gr.components.Textbox(lines=7, label="Ingrese su pregunta"),
35
  outputs="text",
36
  title="Demo Galicia")
37
 
38
- # rebuild storage context
39
- storage_context = StorageContext.from_defaults()
40
- # load index
41
- index = load_index_from_storage(storage_context)
42
  iface.launch(share=True, debug=True)
 
14
 
15
  prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
16
 
17
+ llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
18
 
19
  documents = SimpleDirectoryReader(directory_path).load_data()
20
+
21
+ index = GPTVectorStoreIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
22
+
23
+ index.storage_context.persist(persist_dir="index.json")
24
 
25
  return index
26
 
27
  def chatbot(input_text):
28
  query_engine = index.as_query_engine()
29
+ response = query_engine.query(input_text)
 
30
  return response.response
31
 
32
  iface = gr.Interface(fn=chatbot,
33
+ inputs=gr.components.Textbox(lines=7, label="Ingresa tu pregunta"),
34
  outputs="text",
35
  title="Demo Galicia")
36
 
37
+ index = construct_index("docs")
 
 
 
38
  iface.launch(share=True, debug=True)