Spaces:
Paused
Paused
File size: 1,309 Bytes
5669f53 d1a3943 5669f53 03b394c 5669f53 c2ea10b 5669f53 c2ea10b 5669f53 f2d6127 c2ea10b 5669f53 c2ea10b 5669f53 441fdf4 5669f53 c2ea10b 5669f53 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage
from langchain.chat_models import ChatOpenAI
import gradio as gr
import sys
import os
os.environ["OPENAI_API_KEY"]
def construct_index(directory_path):
max_input_size = 4096
num_outputs = 512
max_chunk_overlap = 0.2
chunk_size_limit = 600
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
documents = SimpleDirectoryReader(directory_path).load_data()
index = GPTVectorStoreIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
index.storage_context.persist(persist_dir="index.json")
return index
def chatbot(input_text):
query_engine = index.as_query_engine()
response = query_engine.query(input_text)
return response.response
iface = gr.Interface(fn=chatbot,
inputs=gr.components.Textbox(lines=7, label="Ingresa tu pregunta"),
outputs="text",
title="Demo Galicia")
index = construct_index("docs")
iface.launch(share=True, debug=True) |